我试图有一个简单的模式出现时,用户点击我的演示应用程序仍在建设中的东西。试图解雇一个简单的角模态导致:无法读取属性'解雇'的未定义
一切工作到我希望用户点击模式上的'关闭'按钮。当他们这样做,他们得到:
TypeError: Cannot read property 'dismiss' of undefined
这是我在我的主控制器:
$scope.underConstruction = function() {
var modalInstance = $modal.open({
templateUrl: 'app/shared/underconstruction.html',
controller: 'ModalInstanceCtrl',
size: 'sm',
resolve: {
'$modalInstance': function() { return function() { return modalInstance; } }
}
});
console.log('modal opened');
modalInstance.result.then(function (response) {
$scope.selected = response;
console.log(response);
}, function() {
console.log('Modal dismissed at: ' + new Date());
});
};
然后在我的ModalInstanceCtrl我:
app.controller('ModalInstanceCtrl', ['$scope', '$modal', function ($scope, $modal, $modalInstance) {
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
}]);
我使用angular- UI版本0.12.0,angularjs版本v1.3.11
命中close()方法,然后引发上述错误。
我环顾了各种结果和问题,看到了有关错误和其他问题的参考,但用例比我的更复杂 - 我的模式只显示一些文本和一个关闭按钮。例如,我found an answer that says:
$modalInstance is made available for injection in the controller by AngularUI Bootstrap implementation. So, we don't need any effort ro "resolve" or make it available somehow.
Stewie正确回答。你应该摆脱这种表示法,并且在缩小脚本时使用* ngmin *或* ngannotate *。 – Ioan 2015-02-05 14:38:43