我无法弄清楚如何在另一个角度控制器中调用方法。 在网页上有另一个角度应用程序。我想使用其他应用程序的一些功能。只要我将其他控制器添加到我的html中,我就会在页面加载时出现此错误:
Unknown provider: documentsServiceProvider <- documentsService <- documentActionsController
我的代码:
angular.module('myApp', [])
.controller("documentActionsController", SomeNameSpace.DocumentActionsController)
.controller('myController', function ($scope) {
标记
<div id="qms-part-docApp" ng-controller="myController" >
<tr ng-repeat="fileInfo in documentList track by $index">
<a ng-controller="documentActionsController" ng-click="addToFavorites()"></a></td>
我想在这个documentActionsController(TypeScript编译)
上调用一个方法var Controllers;
(function (Controllers) {
var DocumentActionsController = (function (_super) {
__extends(DocumentActionsController, _super);
function DocumentActionsController($scope, documentsService, basketService, favoritesService) {
var _this = this;
_super.call(this, $scope);
this.$scope = $scope;
this.documentsService = documentsService;
this.basketService = basketService;
this.favoritesService = favoritesService;
this.init = function () {
_this.$scope.addToFavorites = _this.addToFavorites;
_this.$scope.removeFromFavorites = _this.removeFromFavorites;
_this.$scope.addToBasket = _this.addToBasket;
_this.$scope.removeFromBasket = _this.removeFromBasket;
_this.$scope.markAsRead = _this.markAsRead;
_this.$scope.isItInFavorites = _this.isItInFavorites;
_this.$scope.isItInBasket = _this.isItInBasket;
_this.$scope.isItRead = _this.isItRead;
};
this.addToFavorites = function (id, title, owner, url, icon, path) {
SomeNamespace.addToFavorites(id, title, owner, url, icon, path);
};
this.removeFromFavorites = function (id, path) {
SomeNamespace.removeFromFavorites(id, path);
};
this.addToBasket = function (id, title, owner, url, icon, filename) {
SomeNamespace.addToBasket(id, title, owner, url, icon, filename);
};
this.removeFromBasket = function (id) {
SomeNamespace.removeFromBasket(id);
};
this.markAsRead = function (id, version) {
SomeNamespace.markAsRead(id, version);
};
this.isItInFavorites = function (id) {
SomeNamespace.isItInFavorites(id);
};
this.isItInBasket = function (id) {
SomeNamespace.isItInBasket(id);
};
this.isItRead = function (id, version) {
SomeNamespace.isItRead(id, version);
};
this.init();
}
DocumentActionsController.$inject = [
"$scope",
"documentsService",
"basketService",
"favoritesService"
];
return DocumentActionsController;
答案 0 :(得分:1)
像这样注册services,
angular.module('myApp', [])
.service("documentsService", function(){
// write code
})
.service("basketService", function(){
// write your code
})
.service("favoritesService", function(){
// write your code
})
.controller("documentActionsController", SomeNameSpace.DocumentActionsController)
.controller('myController', function ($scope) {