我試圖有一個簡單的模式出現時,用戶點擊我的演示應用程序仍在建設中的東西。試圖解僱一個簡單的角模態導致:無法讀取屬性'解僱'的未定義
一切工作到我希望用戶點擊模式上的'關閉'按鈕。當他們這樣做,他們得到:
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