Angularjs ngResource '@id'

2019-03-30 08:50发布

问题:

I have a quick question. In angular js where (like which object) does the '@id' come from in the following piece of code from a rails app?

var User = $resource("/users/:id", {id: '@id'});

I know it sets the default id.

Thanks

回答1:

From the AngularJs documentation:

"If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (useful for non-GET operations)."

This means that when calling a non-GET operation, like POST, you can pass the id as one of the fields of the data object you include in the call.