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: And in the controller I have the code: [$ 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 In your case, You can do many things with the 1) Use it in your thoughts in finger expressions. When Controller: HTML: 2) Use the (['./ 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}}}}}}); });
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 ()}}}})}}
$ 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.
console.log () output prints it, because This object is met immediately access the server a chance to respond.
$ Promise is resolved automatically, the view will be updated with your part effort. For example:
$ scope.users = user_resources.getAll ();
& lt; Ul & gt; & Lt; li ng-repeat = "User in User" & gt; {{User Name}} & lt; / li & gt; & Lt; / Ul & gt;
function () function as suggested above @doodeec, but with the correct syntax:
user_resources .get (all). $ Promise Then (function (data) {// do something with data});
Comments
Post a Comment