我正在尝试创建一个简单的演示,我的App Module继承了另一个模块(" testModule"),然后在视图中调用startCtrl控制器来提醒消息。此代码也使用require js。我得到的错误是:
错误:[$ injector:unpr]未知提供者:$ scopeProvider< - $ scope< - testService
侧面说明我试图插入可重复使用的模块。即testModule到主App模块,这个演示将在整个过程中使用。
HTML
<body ng-app="app">
<div ng-controller="StartCtrl">
<input type="button" ng-click="alertUser()" value="AlertUser">
</div>
<script data-main="js/main.js" src="~/Scripts/require.js"></script>
</body>
main.js
require.config({
paths: {
'angular': "../Scripts/angular",
'angular-route': "../Scripts/angular-route",
'angularAMD': "../Scripts/angularAMD",
'jquery': "../Scripts/jquery-1.8.2",
},
shim: {
jquery: {
exports: '$'
},
'angular': ['jquery'],
'angularAMD': ['angular'],
'angular-route': ['angular'],
},
deps: ['app']
});
app.js
define(['angularAMD', 'angular', 'angular-route', 'NewFeature/main'], function (angularAMD) {
var app = angular.module('app', ['testModule','ngRoute']);
return angularAMD.bootstrap(app);
});
NewFeature /主
define(['./testModule','./testService','./feature']);
feature.js文件
define(['angular','./testModule','ngAnimate', 'angular-route'], function () {
angular.module('testModule').controller('StartCtrl, function ($scope, testService) {
$scope.alertUser = function () {
testService.alertService();
}
}])
});
testService.js
define(['./testModule','jquery','angular'], function ($) {
angular.module('testModule').factory("testService", function ($, $scope) {
var proxy = null;
alertService = function () {
alert("servicePassed")
}
return {
alertService: alertService
}
})
});
任何想法??