在angularjs中注入$ dialog时出错

时间:2013-09-03 19:02:19

标签: javascript angularjs

我想在angularjs dialog中展示controller。我正在使用angular-uiangular-strap

在Controller中注入$对话框时出现以下错误:

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>

我的EncouragementController.js使用angular-ui的ui.bootstrap.dialog是

 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' ]);

我跟着angular js unknown provider,但没有回答对我有效。

1 个答案:

答案 0 :(得分:1)

AngularStrap没有$dialog服务。如果您想使用AngularStrap的模态服务,请将其更改为$modal

AngularUI确实有$dialog服务。但是要使用它,您必须将ui.bootstrap模块链接到您的应用。

angular.module('user', [ 'ui', '$strap.directives', 'ui.bootstrap']);

$ modal和$ dialog有不同的API,所以你必须决定要使用哪一个。

现在重要的是要注意AngularStrap和AngularUI在功能上相互重叠(例如,两者都提供导致上述混淆的模态服务)。有什么理由你必须同时使用它们吗?