$ dialog注入导致AngularJS中的错误

时间:2014-07-24 11:29:05

标签: angularjs modal-dialog angular-directive

虽然这个程序在Plunker http://plnkr.co/edit/1RmSI3liMKrE89f9YwFC?p=preview中工作得很好,但是当我在MVC中添加相似内容时,我得到有关角度注入器的错误。 更具体地说,在以下行中:

var app = angular.module('MainCtrl', ['ui.bootstrap']);

app.controller('MainCtrl', ['$scope', '$dialog', function ($scope, $dialog) {

错误如下:

Error: [$injector:unpr] http://errors.angularjs.org/1.2.19/$injector/unpr?p0=%24dialogProvider%20%3C-%20%24dialog v/<@http://localhost:51533/Scripts/angular.min.js:6:443 dc/l.$injector<@http://localhost:51533/Scripts/angular.min.js:36:196 c@http://localhost:51533/Scripts/angular.min.js:34:273 dc/n.$injector<@http://localhost:51533/Scripts/angular.min.js:36:266 c@http://localhost:51533/Scripts/angular.min.js:34:273 d@http://localhost:51533/Scripts/angular.min.js:35:1 g/<.instantiate@http://localhost:51533/Scripts/angular.min.js:35:163 Pd/this.$get</<@http://localhost:51533/Scripts/angular.min.js:67:417 K/<@http://localhost:51533/Scripts/angular.min.js:54:40 q@http://localhost:51533/Scripts/angular.min.js:7:363 K@http://localhost:51533/Scripts/angular.min.js:53:405 f@http://localhost:51533/Scripts/angular.min.js:47:243 f@http://localhost:51533/Scripts/angular.min.js:47:243 z/<@http://localhost:51533/Scripts/angular.min.js:46:374 cc/c/</<@http://localhost:51533/Scripts/angular.min.js:18:279 Zd/this.$get</k.prototype.$eval@http://localhost:51533/Scripts/angular.min.js:112:308 Zd/this.$get</k.prototype.$apply@http://localhost:51533/Scripts/angular.min.js:113:24 cc/c/<@http://localhost:51533/Scripts/angular.min.js:18:237 d@http://localhost:51533/Scripts/angular.min.js:35:27 cc/c@http://localhost:51533/Scripts/angular.min.js:18:145 cc@http://localhost:51533/Scripts/angular.min.js:18:349 Xc@http://localhost:51533/Scripts/angular.min.js:17:432 @http://localhost:51533/Scripts/angular.min.js:213:1 jQuery.Callbacks/fire@http://localhost:51533/Scripts/jquery-2.1.1.js:3073:1 jQuery.Callbacks/self.fireWith@http://localhost:51533/Scripts/jquery-2.1.1.js:3185:7 .ready@http://localhost:51533/Scripts/jquery-2.1.1.js:3391:3 completed@http://localhost:51533/Scripts/jquery-2.1.1.js:3407:2
e/<()angular.min.js (line 92)
Rd/this.$get</<()angular.min.js (line 68)
Zd/this.$get</k.prototype.$apply()angular.min.js (line 113)
cc/c/<()angular.min.js (line 18)
d()angular.min.js (line 35)
cc/c()angular.min.js (line 18)
cc()angular.min.js (line 18)
Xc()angular.min.js (line 17)
angular.min.js()angular.min.js (line 213)
jQuery.Callbacks/fire()jquery-2.1.1.js (line 3073)
jQuery.Callbacks/self.fireWith()jquery-2.1.1.js (line 3185)
.ready()jquery-2.1.1.js (line 3391)
completed()jquery-2.1.1.js (line 3407)
angul

1 个答案:

答案 0 :(得分:0)

我看到你正在使用角度引导,然后注入它的正确方法是

angular.module('yourApp', ['ui.bootstrap']);

不是$ dialog,因为它在此级别未定义

你还必须向控制器注入$对话框

http://plnkr.co/edit/anfWml1umuH7miU4JDhM?p=preview