我有服务
app.service('myService', function() {
this.list = [];
this.execute = function() {
//this.list is reachable here
angular.forEach(AnArrayHere, function(val, key) {
//this.list is not reachable here
});
}
}
即使在控制器中也可以访问
function Ctrl($scope, myService) {
$scope.list = myService.list;
}
有人可以解释一下为什么在 angular.foreach 中无法访问“this.list”以及如何访问“this.list”吗?