0
我似乎无法将工厂中的对象传递给控制器。我知道这应该很简单,但我很难过。角度工厂返回undefined
app.factory('test', [function(){
var fac = {};
fac.users = ['john', 'james', 'jake'];
return fac;
}]);
app.controller('dashboardCtrl', [
'$scope',
'test',
function($scope, test){
$scope.testFunction = function(){
console.log(test.users);
}
}
]);
触发$ scope.testFunction导致控制台中记录的“undefined”。
何时何地激发'$ scope.testFunction'?它似乎工作得很好[JSFiddle](https://jsfiddle.net/4tgohyp3/2/) – Dan
@PenVirus使jsfiddle和向我们展示。这应该很好。 –