Can anybody help me with $ressource 'HEADERS'

868 views
Skip to first unread message

Oelmez

unread,
Sep 26, 2012, 9:08:42 AM9/26/12
to ang...@googlegroups.com
Hey,
i want to set Headers in my Request and send it to my localServer.
I don't know if i'm doing it right.

Here is a codesnippet:

function LoginCtrl($scope,LoginService, $resource) {
$scope.login = function (id,password) {
var UserStatus = $resource('/nancy/api/login/', {},
{'Login': {method: 'POST',isArray: false,headers:{'id':id,'pass':password}}
});
$scope.Loginstatus = UserStatus.Login({ Benutzer: id, Password: password}, function () {
$scope.response=$scope.Loginstatus.status; 
});
};   
}

LoginCtrl.$inject = ['$scope','LoginService','$resource'];

i set the headers where i define the action. is this right or did i forget anything?

Pawel Kozlowski

unread,
Sep 26, 2012, 1:39:23 PM9/26/12
to ang...@googlegroups.com
Hi!

The ability to define headers on a resource was only added in:
https://github.com/angular/angular.js/commit/fbdab513dd48f667ad857030cf4b3481ecdd9097#src/ngResource/resource.js

From what I can see this commit is only present in the master branch
so probably didn't make it into any release.
The strange thing is that both 1.0.2 and 1.1.0 seem to be released but
where not tagged (!):
https://github.com/angular/angular.js/tags

which I find a bit strange...

Anyway, for your problem, you should just probably grab the
ngResource.js file from the master.

Hope this helps,
Pawel
> --
> 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.
> Visit this group at http://groups.google.com/group/angular?hl=en.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Almog

unread,
Sep 26, 2012, 8:14:41 PM9/26/12
to ang...@googlegroups.com, eneso...@yahoo.de
I'm using the latest build and I'm able to set headers and even custom headers. You need to set it under the default for $http, $resource has the $http dependance. 

Here is a code example 

$http.defaults.headers.common['Authorization'] = 'Token token=' + data.access_token;
Reply all
Reply to author
Forward
0 new messages