gpt4 book ai didi

javascript - 从外部按钮清除 Angular Bootstrap UI 选项卡集中与文本区域关联的 ng-model

转载 作者:行者123 更新时间:2023-11-30 05:33:52 25 4
gpt4 key购买 nike

我使用 angular bootstrap ui tabset 创建了两个选项卡,这两个选项卡都有 textareasng-model 相关联,我在 tabset 外有一个清除按钮,我想在用户按下清除按钮时清除事件选项卡中 textAreang-model。做这个的最好方式是什么?这是我到目前为止所做的。

HTML

<tabset>
<tab heading="Tab One">
<textarea data-ng-model="data.tabOne" class="form-control"></textarea>
</tab>
<tab heading="Tab two">
<textarea data-ng-model="data.tabOne" class="form-control"></textarea>
</tab>
</tabset>
<button ng-click="clearFn()" class="btn btn-default btn-float-left">Clear</button>

Controller

.controller('myController', ['$scope', function ($scope) {
$scope.data = {
tabOne: '',
tabTwo: ''
};

$scope.ClearFn = function () {
// I want to clear the model of the active tabs textArea here.
};
}]);

最佳答案

您可以使用选项卡的 active 属性来查找当前事件的选项卡。

<tabset>
<tab heading="Tab One" active="activeState.tabOne">
<textarea ng-model="data.tabOne" class="form-control"></textarea>
</tab>
<tab heading="Tab Two" active="activeState.tabTwo">
<textarea ng-model="data.tabTwo" class="form-control"></textarea>
</tab>
</tabset>

在 Controller 中:

.controller('myController', ['$scope', function ($scope) {
$scope.data = {
tabOne: 'ONE',
tabTwo: 'TWO'
};

$scope.activeState = {};

$scope.clearFn = function() {
// I want to clear the model of the active tabs textArea here.
for (var key in $scope.activeState) {
if ($scope.activeState[key]) {
// active tab found
$scope.data[key] = '';
return;
}
}
};
}])

示例 Plunker: http://plnkr.co/edit/ioJKua5XTeetBcvjGity?p=preview

关于javascript - 从外部按钮清除 Angular Bootstrap UI 选项卡集中与文本区域关联的 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25130595/

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