ui bootstrap modal 的控制器“未定义" [英] ui bootstrap modal's controller 'is not defined'
问题描述
我正在尝试使用 ui-bootstrap 0.6 中的 modal 指令
i am trying to use the modal directive from ui-bootstrap 0.6
这是来自 ui-bootstrap 页面的默认工作 plunker:
here is the working default plunker from the ui-bootstrap page:
http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=preview
现在,我尝试使编码风格适合 angular-seed 风格,以将其包含在这样的应用程序中:
now, i tried to make the coding style fits angular-seed style to include it in one app like this :
http://plnkr.co/edit/Y59rwlcNpQdijKtmjOPy?p=preview
angular.module('MyModal', ['ui.bootstrap', 'MyModal.controllers']);
angular.module('MyModal.controllers', [])
.controller('ModalDemoCtrl', [ '$scope', '$modal', '$log', function ($scope, $modal, $log) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.open = function () {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
}])
.controller('ModalInstanceCtrl', [ '$scope', '$modalInstance', 'items', function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
但它给出了一个错误ReferenceError: ModalInstanceCtrl is not defined
如何使用这种定义控制器的方式来完成这项工作?
how can i make this work using this way of defining controllers ?
推荐答案
以 String 形式提供控制器名称,与您在路由定义、指令等中所做的完全一样:
Provide controller name as String, exactly as you would do in route definitions, directives etc.:
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
这篇关于ui bootstrap modal 的控制器“未定义"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!