我有一個供應商:取消設置對象屬性
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); // the correct object
});
this.adviceCategories = [
// available in the controller
];
}
return{
AdviceList: function(){
return new AdviceList();
}
}
}
});
而且,我有這個控制器:
AdviceList.controller('AdviceListCtrl',function($scope,$adviceList){
var adv = $adviceList.AdviceList();
$scope.treatments = adv.treatments; // undefined
});
爲什麼,控制器的$scope.treatments
撐不定,this.treatments
但是供應商裏面,是正確填寫?另外,我的控制器中還有adviceCategories
。
謝謝。你是否介意分享一個簡單例子的相關鏈接,如果你巧合的有一個? – user2422960