Sunday 15 May 2011

c# 4.0 - Using angulars ngResource get method -


I have a basic controller defined in C #, its only purpose is to identify which current user is

  Namespace ProjectName.Controllers {Public Class UserController: ApiController {// GET API / User / Public String (Go) {User User.Identity.Name; }}}   

I have an NGSOS defined to see that controller

  cript.factory ('user', function ($ resource) { Return $ resource ('/ API / user')});   

Finally I try to get that user in my angle controller

  $ scope.checkIfAuth = function () {$ scope.user = User.get (); Console.log ($ scope.user); If ($ scope.user === '"ds //: lemijser' ') {console.log (" success "); }};   

Problem $ scope.user is a resource object that looks like this

  resources {$ get: function, $ save: function, $ query: "Remove: Function, Delete: Function} 0:" "1:" D "2:" S "3:" \ "4:" \ "5:" l "6:" E "7:" M "8 : "I" 9: "e" 10: "s" 11: "z" 12: "r" 13: "" __proto__: resource   

anyway just containing my username User.query () returns only a blank table to get the string.

I Looking into the implementation of coalition Q Wired Library () I am still working with MVC 4.0 and it has become more flexible than NGRSORS.

However, in relation to your question, here is your problem. That you are requesting an async server your server is starting to react to synchronous. Okay, the data is still not getting (why are you looking at an empty array []) This empty array is basically telling the server "Hey, There is a good working protocol on the ripe http request, we are getting your data, this is an empty array to prove where we will get the data from you. "

In other things, your problem is That you are examining its (even roughly) one before checking the value of $ scope.user.

You have two options (at least in my knowledge) for simple improvements: You can set $ scope.user to respond to a different function or server in another service, and then Once it is received, you can use the feedback. Or (better 'simple' fix) service, which essentially tells your system that "until my ASCNC request is made cool, and I have my data."

No comments:

Post a Comment