角引导模式造成严二错误,不知道为什么 [英] Angular bootstrap modal causing strict-di error, not sure why
问题描述
奇怪的问题,采用了棱角分明的UI自举莫代尔我没有问题,在所有角1.3测试版16,但是如果我能NG-严格二模我收到以下错误:
Weird problem, using Angular UI bootstrap modal I have no issues at all with Angular 1.3 beta 16, however if I enable ng-strict-di mode I get the following error:
Error: [$injector:strictdi] function($scope, $modalInstance) is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.3.0-beta.16/$injector/strictdi?p0=function(%24scope%2C%20xmodalInstance)
at http://localhost:3000/vendor/angular.js:78:12
at annotate (http://localhost:3000/vendor/angular.js:3353:17)
at invoke (http://localhost:3000/vendor/angular.js:4037:21)
at Object.instantiate (http://localhost:3000/vendor/angular.js:4070:23)
at http://localhost:3000/vendor/angular.js:7451:28
at http://localhost:3000/vendor/ui-bootstrap-tpls-0.11.0.min.js:8:28715
at wrappedCallback (http://localhost:3000/vendor/angular.js:11616:81)
at http://localhost:3000/vendor/angular.js:11702:26
at Scope.$eval (http://localhost:3000/vendor/angular.js:12797:28)
at Scope.$digest (http://localhost:3000/vendor/angular.js:12609:31)
奇怪的是,这是不是在一个指令或服务,这是仅次于我的网页的一个剧本。我知道我在做一个控制器有,但......好吧我不知道在这一点上。下面是生成错误的code:
The weird thing is this is not in a directive or service, it's just the script behind one of my pages. I know I'm making a controller there but...well I'm not sure at this point. Here is the code that generated the error:
//=================
//MODAL PROMPTER
//=================
var Prompt = function(title, prompt) {
var modalInstance = $modal.open({
template: '<div class="modal-header"><h3 class="modal-title">' + title + '</h3></div><div class="modal-body"><p>' + prompt + '</p></div><div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>',
controller: ModalInstanceCtrl,
size: 'sm'
});
modalInstance.result.then(function(result) {
console.log('Modal OK');
}, function() {
console.log('Modal dismissed');
});
};
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close(true);
};
$scope.cancel = function() {
$modalInstance.dismiss(false);
};
};
//end of modal
//==================
//call it immediately to see the error
Prompt('myTitle', 'myMessage');
我不知道怎样和为什么我得到的错误。如果我关闭了严格的二它完美。任何想法?
I'm not sure how or why I'm getting the error. If I turn off strict-di it works perfectly. Any ideas?
推荐答案
您需要手动宣传您的依存关系控制器既然你的 NG-严格二
启用。
You need to manually advertise your dependencies for the controller since you have ng-strict-di
enabled.
function ModalInstanceCtrl ($scope, $modalInstance) { //or var ModalInstanceCtrl = function(...
$scope.ok = function () {
$modalInstance.close(true);
};
$scope.cancel = function () {
$modalInstance.dismiss(false);
};
};
ModalInstanceCtrl.$inject = ['$scope', '$modalInstance'];
这篇关于角引导模式造成严二错误,不知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!