i am trying to use the modal directive from ui-bootstrap 0.6
我尝试使用ui-bootstrap 0.6中的模态指令。
here is the working default plunker from the ui-bootstrap page:
以下是ui-bootstrap页面的工作默认插值:
http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=preview
http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=preview
now, i tried to make the coding style fits angular-seed style to include it in one app like this :
现在,我试着让编码风格适合angular-seed风格,将它包含在这样一个应用程序中:
http://plnkr.co/edit/Y59rwlcNpQdijKtmjOPy?p=preview
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');
};
}]);
but it's giving an error ReferenceError: ModalInstanceCtrl is not defined
但是它给出了一个错误引用错误:ModalInstanceCtrl没有定义。
how can i make this work using this way of defining controllers ?
我如何用这种定义控制器的方法来做这个工作?
2 个解决方案
#1
51
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;
}
}
});
#2
1
You can use quotes as the other answer suggests, or you can also do as the example in the docs and define the variable:
您可以使用引号作为其他答案,或者您也可以作为文档中的示例,并定义变量:
var ModalInstanceCtrl = function ($scope, $modalInstance, items) { ... }
var ModalInstanceCtrl = function ($scope, $modalInstance, items){…}
#1
51
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;
}
}
});
#2
1
You can use quotes as the other answer suggests, or you can also do as the example in the docs and define the variable:
您可以使用引号作为其他答案,或者您也可以作为文档中的示例,并定义变量:
var ModalInstanceCtrl = function ($scope, $modalInstance, items) { ... }
var ModalInstanceCtrl = function ($scope, $modalInstance, items){…}