下面我有一个带控制器和服务的简单表格。当我提到['angucomplete-alt']
HTML
<div ng-controller="Hell">
<input type="button" ng-click="Hello()" value="Save" />
</div>
MyApp.Js
var aap = angular.module('MyApp', ['angularUtils.directives.dirPagination','angucomplete-alt'])
aap.controller('myhmectrl', function ($scope) {
$scope.msg = "Hello Angular....";
})
Conroller.Js
(function () {
angular.module('MyApp', ['angucomplete-alt'])
.controller('Hell', function ($scope, Myservices) {
$scope.Hello = function () {
alert('ok ctrls');
var xx = Myservices.GetSer();
}
});
})
Service.Js
(function () {
angular.module('MyApp', ['angucomplete-alt'])
.service('Myservices', function ($http) {
this.GetSer = function () {
alert('pk Servicess....')
}
})
})
答案 0 :(得分:0)
在控制器中,如果要传递依赖项,它将创建一个新模块并再次实例化,删除依赖项
它应该是
angular.module('MyApp').controller('Hell', function ($scope, Myservices) {
}
答案 1 :(得分:0)
也许你没有为angucomplete-alt包含js文件?
答案 2 :(得分:0)
访问模块时需要删除依赖关系数组。修改您的文件如下:
<强> Controller.js 强>
(function () {
angular.module('MyApp')
.controller('Hell', function ($scope, Myservices) {
$scope.Hello = function () {
alert('ok ctrls');
var xx = Myservices.GetSer();
}
});
})
<强> Service.js 强>
(function () {
angular.module('MyApp')
.service('Myservices', function ($http) {
this.GetSer = function () {
alert('pk Servicess....')
}
})
})