我想将One Controller注入服务。AngularJS:如何将Controller注入服务?
我用AngularJs和Laravel和glup-NG-注释。
/* DialogController*/
(function(){
"use strict";
angular.module("music.controllers").controller('DialogController', function($scope, $mdDialog){
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.answer = function(answer) {
$mdDialog.hide(answer);
};
});
})();
这是服务
/* Service */
(function(){
"use strict";
angular.module("music.services").factory('DialogService', function($mdDialog, DialogController){
return {
fromTemplate: function(template, $scope) {
var options = {
controller: DialogController,
templateUrl: template
};
if ($scope){
options.scope = $scope.$new();
}
return $mdDialog.show(options);
},
alert: function(title, content){
$mdDialog.show(
$mdDialog.alert()
.title(title)
.content(content)
.ok('Ok')
);
}
};
});
})();
我有这样的错误
错误:[$注射器:unpr]未知提供商:DialogControllerProvider < - DialogController < - DialogService
工厂/服务可以拥有自己的控制器!您不能将控制器添加/注入到服务/工厂! –
你试图把车放在马前。 – JLRishe
看看这个JS代码,第82和108行,http://codepen.io/kyleledbetter/pen/gbQOaV –