angularjs - Why is my Angular service not returning data -


I am using folder structure for services inside and inside the app and I have the following code: (['./ module'], function (services) {'strict use'; services.factory ('user_resources', ['$ resource', '$ location', function ( $ Resource, $ location) {return $ resource ("", {}, {'getAll': {method: "GET", url: 'JSON / myList.JSON', IARRA: true}}}}}}); });

And in the controller I have the code:

  define (['./ module'], function (controller) {'strict use' ; Controller .controller ('myListCtrl', ['Phone', 'Phone1', 'loginForm', '$ scope', '$ http', 'user_resources', 'credit card', ceremony (phone, phone1, loginform, $ scope) , $ Http, user_resources, credit card) {console.log (user_resources.getAll ()}}}})}}   

[$ promise: object, $ solution: False] how to get data from it?

I did what has been done, but in my case it is Gives data directly to the tutorial and

Note that from a $ resource server gives an object immediately before the data is received, this object has the property named $ promise when the response is finally received from the server, then $ promise Is resolved and the object will now include the data.

In your case, console.log () output prints it, because This object is met immediately access the server a chance to respond.

You can do many things with the $ resource returned :

1) Use it in your thoughts in finger expressions. When $ Promise is resolved automatically, the view will be updated with your part effort. For example:

Controller:

  $ scope.users = user_resources.getAll ();   

HTML: & lt; Ul & gt; & Lt; li ng-repeat = "User in User" & gt; {{User Name}} & lt; / li & gt; & Lt; / Ul & gt;

2) Use the function () function as suggested above @doodeec, but with the correct syntax:

  user_resources .get (all). $ Promise Then (function (data) {// do something with data});    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -