错误在angularjs中注入$ dialog
我想从angularjs controller
显示一个dialog
。 我正在使用angular-ui和角度绑带
在Controller中注入$ dialog时出现以下错误:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.0rc1/$injector/unpr?p0=%24dialogProvider%20%3C-%20%24dialog
at Error (<anonymous>)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:6:450
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:31:145
at Object.c [as get] (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:28:296)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:31:213
at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:28:296)
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:28:473)
at Object.instantiate (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:30:123)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:58:153
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js:46:383
我的ApplicationResources.groovy
angularJs { resource url:'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular.min.js' }
angularUI {
dependsOn 'angularJs'
dependsOn 'jquery'
dependsOn 'googleMaps'
resource url:'https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.css',attrs:[rel: "stylesheet", type:'css']
resource url:'https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js'
resource url:'https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui-ieshiv.min.js'
}
angularStrap {
dependsOn 'angularJs'
dependsOn 'bootstrapJs'
dependsOn 'datepicker'
resource url: 'https://cdnjs.cloudflare.com/ajax/libs/angular-strap/0.7.4/angular-strap.min.js'
resource url: 'js/angular-strap/datepicker.js'
resource url: 'js/angular-strap/timepicker.js'
}
userJs { resource url:'js/user.js' }
我的user.gsp
<html ng-app="user">
<r:require modules="bootstrapJs" />
<r:require modules="userJs" />
<r:require modules="angularJs" />
</html>
我的使用angular-ui的ui.bootstrap.dialog的EncouragementController.js是
function EncouragementController($scope, $http, $dialog, encouragementService) {
//
$scope.showMessage = function(message){
var title = 'Alert';
var msg = message;
var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}];
$dialog.messageBox(title, msg, btns)
.open()
.then(function(result){
});
};
}
EncouragementController.$inject = [ '$scope', '$http', '$dialog', 'encouragementService' ];
我的app.js
var user = angular.module('user', [ 'ui', '$strap.directives' ]);
我跟着角js未知提供者,但没有答案在那里为我工作。
AngularStrap没有$dialog
服务。 如果您想使用AngularStrap的模式服务,请将其更改为$modal
。
AngularUI确实有一个$dialog
服务。 但为了使用它,您必须将ui.bootstrap
模块链接到您的应用程序。
angular.module('user', [ 'ui', '$strap.directives', 'ui.bootstrap']);
$模式和$对话框有不同的API,所以你必须决定你想使用哪一个。
现在需要注意的是AngularStrap和AngularUI在功能上相互重叠(例如,两者都提供导致上述混淆的模式服务)。 你有什么理由必须使用两者吗?
链接地址: http://www.djcxy.com/p/77631.html