gpt4 book ai didi

jquery - bootstrap modal,angularjs ng-click 获取按钮值

转载 作者:行者123 更新时间:2023-12-01 04:45:59 26 4
gpt4 key购买 nike

我有一个按钮,可以打开带有列表(层次结构)的引导模式,我希望将选定列表 li 值显示为放入 $scope 中的按钮值这是链接 jsfiddle 来了解我的需求。 jsfiddle

最佳答案

您需要做的事情可以通过使用 ui-bootstrap 来实现库,特别是它的 modal 指令。

您不需要像在 fiddle 中那样使用 jQuery。

编辑:这是一个 plunk 作为您需要执行的操作的示例。

JavaScript

angular
.module('modalDemo', ['ui.bootstrap'])
.controller('DemoCtrl', function ($scope, $modal) {

console.log("in angular");

$scope.selected = { name: 'none' };

$scope.open = function() {

var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 'lg'
});

modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
});
};
})
.controller('ModalInstanceCtrl', function ($scope, $modalInstance) {

$scope.setSelectedSegment = function (value) {

$scope.selected = value;
$modalInstance.close($scope.selected);
};

$scope.categoryList = [
{ name: 'Catégorie 1' },
{
name: 'Catégorie 2',
segments: [
{
name: 'Segment 1',
values: [
{ name: 'Valuer 1' },
{ name: 'Valuer 2' }
]
},
{ name: 'Segment 2' }
]
},
{
name: 'Catégorie 3',
segments: [
{ name: 'Segment 1' },
{ name: 'Segment 2' }
]
},
{ name: 'Catégorie 4' },
{ name: 'Catégorie 5' }
];
});

HTML

<div class="container" ng-app="modalDemo">
<div ng-controller="DemoCtrl" class="container">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">Sélection de la segmentation</h3>
</div>
<div class="modal-body">
<div class="dd" id="nestable">
<ol class="dd-list">
<li class="dd-item" ng-repeat="category in categoryList">

<div class="dd-handle">{{ category.name }}</div>

<ol class="dd-list" ng-if="category.segments">
<li class="dd-item" ng-repeat="segment in category.segments">

<div class="dd-handle">{{ segment.name }}</div>

<ol class="dd-list" ng-if="segment.values">
<li class="dd-item" ng-repeat="value in segment.values">
<div class="dd-handle" value="valeur1" ng-click="setSelectedSegment(value)">{{ value.name }}</div>
</li>
</ol>
</li>
</ol>
</li>

Selected: <b>{{ selected.name }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
<button class="btn btn-default" ng-click="open()">{{ selected ? selected.name : 'Segmentation' }}</button>
</div>
</div>

关于jquery - bootstrap modal,angularjs ng-click 获取按钮值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29745452/

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