Feedback on http://docs.angularjs.org/#!/api/angular.service.$resource

291 views
Skip to first unread message

Brent Dunklau

unread,
Apr 11, 2012, 1:46:13 PM4/11/12
to ang...@googlegroups.com, Brent Dunklau
Hi there,
I read http://docs.angularjs.org/#!/api/angular.service.$resource and wanted to ask about this statement:

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

I'm trying to submit form data to a jetty server.

I have a User service declared like this:

angular.service('User', function($resource){
  return $resource('/api/users/:userId', {}, {
    query: {method:'GET', params:{userId:'@id'}, isArray:true},
    save: {method:'POST', params:{first:'@first', last:'@last', email:'@email', username:'@username', password:'@password', bio:'@bio'}}
  });
});


I have a user registration form that looks like this: 

<div ng:controller="UserCtrl">
<form ng:submit="newUser()">
  <div><input maxlength="140" value="" placeholder="First Name" type="text" name="first" /></div>
  <div><input maxlength="140" value="" placeholder="Last Name" type="text" name="last" /></div>
  <div><input maxlength="140" value="" placeholder="Email" type="text" name="email" /></div>
  <div><input maxlength="140" value="" placeholder="Username" type="text" name="username" /></div>
  <div>
    <div><input name="password" type="password" placeholder="Password" value="*******" /></div>
    <div><input name="passwordAgain" type="password" placeholder="Password Again" value="*******" /></div>
  </div>
  <div><input value="" placeholder="Date of Birth" type="text" name="dateOfBirth" /></div>
  <div><input maxlength="1028" value="" placeholder="Profile Pic" type="text" name="profilepic" /></div>
  <div><textarea rows="10" placeholder="Bio" name="bio" cols="50"></textarea></div>
  <div class="row">
    <div class="span1">Cancel</div>
    <div class="span1"><input type="submit" value="Create" /></div>
  </div>
</form>
</div>


And I have a UserCtrl object that looks like this:

function UserCtrl(User_) {
  var scope = this;
 
  scope.newUser = function() {
    User_.save({first:scope.first, last:scope.last, username:scope.username, email:scope.email, password:scope.password, bio:scope.bio});
   
  }
 
}


When User_.save() is called, the web server receives a POST url that looks like this...   /api/users?first=@first&last=@last&email=@email

Rather than evaluating @first, @last etc, these are being passed through as literals.

Any clue what I'm doing wrong?


thanks
Brent

Vojta Jína

unread,
Apr 11, 2012, 5:53:01 PM4/11/12
to ang...@googlegroups.com
It works if you specify defaults as a second argument:

$resource('/some/:param', {param: '@name'}, {});

I guess there is a bug, that it does not work for params specified for particular action, can you submit an issue https://github.com/angular/angular.js/issues/new

V.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Brent

unread,
Apr 12, 2012, 9:46:47 AM4/12/12
to AngularJS
No problem...

https://github.com/angular/angular.js/issues/875


On Apr 11, 4:53 pm, Vojta Jína <vojta.j...@gmail.com> wrote:
> It works if you specify defaults as a second argument:
>
> $resource('/some/:param', {param: '@name'}, {});
>
> I guess there is a bug, that it does not work for params specified for
> particular action, can you submit an issuehttps://github.com/angular/angular.js/issues/new
>
> V.
>
>
>
>
>
>
>
> On Wed, Apr 11, 2012 at 10:46 AM, Brent Dunklau <bdunk...@yahoo.com> wrote:
> >  Hi there,
> > I readhttp://docs.angularjs.org/#!/api/angular.service.$resourceand

Vojta Jína

unread,
Apr 12, 2012, 4:03:07 PM4/12/12
to ang...@googlegroups.com
Thanks

V.
Reply all
Reply to author
Forward
0 new messages