qmar
qmar
1
Elo Mirki z #angular #angularjs

var User = $resource('/user/:userId', {userId:'@id'});
User.get({userId:123})
.$promise.then(function(user) {
$scope.user = user;
});

Po co ten '@id'?

Przykład z dokumentacji tutaj: https://docs.angularjs.org/api/ngResource/service/$resource
  • Najlepsze
  • Wszystkie komentarze
z.....2
z.....2
@qmar: do API na backendzie idzie po prostu /user/123 W tym przypadku ustawiasz to na sztywno ale możesz to wykonywać w kodzie jako parametr.
qmar
qmar Autor
0
@zenon1002: mogę prosić o przykład?
z.....2
z.....2
@qmar:

Nie jestem przy kompie ale masz przykład z apki google:

phonecatServices.factory('Phone',
z.....2
z.....2
qmar
qmar Autor
0
@zenon1002: W tym co przytoczyłeś nie ma fragmentu z małpą (@) o który pytałem
z.....2
z.....2
@qmar:
If the parameter value is prefixed with @ then the value for that parameter will be extracted from the corresponding property on the data object (provided when calling an action method). For example, if the defaultParam object is {someParam: '@someProp'} then the value of someParam will be data.someProp.
laki1
@qmar: jest opisane w linku

If the parameter value is prefixed with @ then the value for that parameter will be extracted from the corresponding property on the data object (provided when calling an action method). For example, if the defaultParam object is {someParam: '@someProp'} then the value of someParam will be data.someProp.
Jurigag
@qmar: @ oznacza że userId będzie pobrane z obiektu który przekażesz z pola id, jak podasz z palca to userId to po prostu nadpisze ono to zachowanie