【发布时间】:2017-08-05 04:46:52
【问题描述】:
我正在 1.6.x 中编写 angularjs 应用程序...我遇到了 component() 问题,其中 $onInit() 看不到任何已定义的变量...
每个变量都是未定义的
这是我的代码..
angular.module('carFilter', []).
component('carFilter', {
controller: function (carFactory, $http) {
this.service = carFactory;
this.updatedObj = {};
//when i put breakpoint here on chrome, i can see the factory obj.. but..
//when it goes to oninit, init can not see this obj
this.$onInit = function () {
this.testing = 'a';
console.log(this.service); //th
loadFilter().then(function (result) {
updateFilter(result)
});
};
function loadFilter() {
//$http here to return promise
}
function updateFilter(responseData) {
//using response data to update i wanted to update the this.updatedObj
this.updatedObj = responseData;
//but here, when this function is triggered, every object is undefined...
//I tried to put this.sercie and this.updatedObj in $onInit(), but it was still getting UNDEINFED....
//it could not see this.testing either...
//how can i update object in the controller??
}
},
templateUrl: 'someURL'
});
提前谢谢你...
【问题讨论】:
标签: javascript angularjs components