我想根據某些條件打開模式彈出窗口。不過,我得到以下錯誤 Error: [$injector:unpr] http://errors.angularjs.org/1.2.3/$injector/unpr?p0=%24modalProvider%20%3C-%20%24modal at Error (<anonymous>)
以下是我的代碼:「ui.bootstrap」包含在應用程序中。
angular.module('myApp').controller('myController', function ($scope, $timeout, $location, $window, $log, $rootScope, $modal) {
$scope.selectRow = function (position) {
$scope.changed = false;
if ($scope.select !== undefined && $scope.selectedRow !== position){
$scope.changed = true;
$scope.open();
}
$scope.select = position;
};
$scope.open = function() {
console.log('Opening modal');
var modalInstance = {
templateUrl: 'modal.html',
dialogClass: 'modal-selection',
controller: ModalInstanceCtrl
};
$modal.open(modalInstance);
};
var ModalInstanceCtrl = function ($modalInstance) {
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
});
我的HTML:
<div id="modal-select" >
<h3>
Choose appropriate change
</h3>
<div>
<ul>
<li><a href="#">Change 1</a></li>
<li><a href="#">Change 2</a></li>
<li><a href="#">Change 3</a></li>
<li><a href="#">Change 4</a></li>
</ul>
</div>
<div>
<button class="button" ng-click="cancel()">
Cancel
</button>
<button class="button" ng-click="ok()">
Done
</button>
</div>
</div>
ui.bootstrap是已經添加到父app.js文件中,原因是舊版本的ui.bootstrap。感謝您的意見。 –
@Oleg - 這完全正確!只要我將它添加到我的模塊,它就完美了! – webdad3