【发布时间】:2013-07-17 12:18:53
【问题描述】:
我有一个提供者:
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 在我的控制器中可用。
【问题讨论】:
标签: javascript oop object angularjs