javascript - Unset object property -


i have provider:

advicelist.provider('$advicelist',function(){     this.$get = function ($rootscope,$document,$compile,$http,$purr){          function advicelist(){            $http.post('../sys/core/fetchtreatments.php').success(function(data,status){                 this.treatments = data;                 console.log(this.treatments); // correct object             });              this.advicecategories = [                 // available in controller             ];          }         return{              advicelist: function(){                 return new advicelist();             }         }     } }); 

further, have controller:

advicelist.controller('advicelistctrl',function($scope,$advicelist){     var adv = $advicelist.advicelist();     $scope.treatments = adv.treatments; // undefined }); 

why it, controller's $scope.treatments stays undefined, this.treatments inside provider however, filled correctly? also, advicecategories available in controller.

the call teatment async in nature results may not have been populated when try assign them.

so here

var adv = $advicelist.advicelist(); $scope.treatments = adv.treatments;  //the treatments filled after server call over. 

you need rewrite code in way assign scope property on success callback.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -