Friday 15 May 2015

angularjs - Using a factory with $http promise returns empty object -


I have this simple factory that receives the data file and saves it in service. Data:

 <("TTI"), ("edit", ["$ http", function ($ http) {var service = {} service.data = {} service .getTikis = function ) {$ Http. ("Data / Tickets Jason"). Success (Tasks) {console.log (tikki) service.data = tikis}} return service}])  
< P> Then, in the controller I give it to the $ scope. This is the first empty course, but when $ resolves the http, it will have to update my factory and in return with the data returned service.data object Has to be updated.

  The angular.module ('tiki'). Controller ("Tiki.controller.settings.edit", ["$ scope", "editTiki", function ($ Range, editTiki) {// Ticket should be returned $ scope.preview = EditTiki.data editTiki.getTikis () $ scope .showEditTikiObject = function () {console.log ($ scope.preview)}}])  

However, to test the contents of data This function is for and it gives a blank object. Why is it?

After you are reassigning service.data = tikis on this $ scope.preview

G should.

  Angular Module ("Pinned") ("EditTiki", ["$ http", function ($ http) {var service = {}; service.data = {}; service.getticis = function () {return $ http.get ("data / box.jason "). Ceases (function) {console.log (tikki) service.data = tikis; return service.data;})}; return service;}]); Controller ("tiki.controller.settings.edit", ["$ scope", "editTiki", function ($ scope, editTiki) {editTiki.getTikis (). Then (function () {$ Scope.preview = editTiki.data ;}); $ Scope.showEditTikiObject = function () {console.log ($ scope.preview);}}}])  

No comments:

Post a Comment