gpt4 book ai didi

angularjs - ui bootstrap modal 的 Controller 'is not defined'

转载 作者:行者123 更新时间:2023-12-02 19:34:34 24 4
gpt4 key购买 nike

我正在尝试使用 ui-bootstrap 0.6 中的模式指令

这是 ui-bootstrap 页面中工作的默认插件:

http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=preview

现在,我尝试使编码风格适合 Angular ​​度种子风格,将其包含在一个应用程序中,如下所示:

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未定义

我如何使用这种定义 Controller 的方式来完成这项工作?

最佳答案

将 Controller 名称提供为字符串,就像在路由定义、指令等中所做的那样:

var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});

关于angularjs - ui bootstrap modal 的 Controller 'is not defined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19432592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com