为什么没有注入WizardPageSchoolclassCodesFactory工厂?它永远是空的!
我的Chrome控制台中的错误是:
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- WizardPageSchoolclassCodesFactory
angular.module('myModule').controller('WizardMainController', function ($scope, WizardPageSchoolclassCodesFactory) {
// do stuff with data
});
'use strict';
angular.module('myModule').factory('WizardPageSchoolclassCodesFactory', function($scope) {
this.getData = function()
{
return "hello";
}
});
答案 0 :(得分:0)
如果您想将范围传递到工厂,可以这样做:
app.factory('WizardPageSchoolclassCodesFactory', function() {
return function(scope){
this.getData = function()
{
scope.test = "test";
return "hello";
}
}
});
在控制器中,您必须创建工厂的新实例并在构造函数中传递范围:
var factory = new WizardPageSchoolclassCodesFactory($scope);
然后您可以使用声明的工厂方法:
factory.getData();