error injecting $dialog in angularjs
I want to show a dialog
from angularjs controller
. I am using angular-ui and angular-strap
While injecting $dialog in Controller I get the following error :
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
My 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' }
My user.gsp
<html ng-app="user">
<r:require modules="bootstrapJs" />
<r:require modules="userJs" />
<r:require modules="angularJs" />
</html>
My EncouragementController.js using angular-ui's ui.bootstrap.dialog is
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' ];
My app.js
var user = angular.module('user', [ 'ui', '$strap.directives' ]);
I followed angular js unknown provider, but no answer there worked for me.
AngularStrap does not have a $dialog
service. Change it to $modal
if you want to use AngularStrap's modal service.
AngularUI does have a $dialog
service. But in order to use it, you must link the ui.bootstrap
module to your app.
angular.module('user', [ 'ui', '$strap.directives', 'ui.bootstrap']);
$modal and $dialog has different APIs, so you must decide which one you want to use.
Now it is important to note that AngularStrap and AngularUI overlaps each other a great deal in functionality (eg both provide modal service causing the above confusion). Is there any reason you have to use both?
链接地址: http://www.djcxy.com/p/77632.html上一篇: UI路由器