【发布时间】:2016-05-27 11:26:05
【问题描述】:
我正在学习 angular+ES6 编码。
test.controller.js
class TestSecIndexController {
constructor (TestSecService,$q) {
this.src = require('./../images/2.jpg');
this._TestSecService = TestSecService;
let promises = [
this.getPeopleList()
];
$q.all(promises).then(function (){
console.log(this.people);
})
}
getPeopleList(){
return this._TestSecService.getPeopleList().then(function(res){
this.people = res.data; //line: 22
});
}
static testSecIndexController(TestSecService,$q){
return new TestSecIndexController(TestSecService,$q);
}
}
TestSecIndexController.testSecIndexController.$inject = ['TestSecService','$q'];
export default angular.module ('test2.index.controller', [])
.controller ('testSecIndexController', TestSecIndexController.testSecIndexController)
如果这样做,就会出现错误:
angular.js:13550 TypeError: 无法设置未定义的属性“人” 在 index.controller.js:22
this.src可以设置成功,为什么this.people不能设置?
【问题讨论】:
标签: javascript angularjs ecmascript-6