使用angularjs选项卡指令时如何通过单击按钮移动到第二个选项卡 [英] How to move to second tab on click of a button when using angularjs tab directive
本文介绍了使用angularjs选项卡指令时如何通过单击按钮移动到第二个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 angular tab 指令.JS 小提琴的链接是AngularJs Tab Directive.我的问题是如何通过单击按钮从第一个选项卡移动到第二个选项卡?谢谢
Hi I'm using angular tab directive.The link for JS fiddle is AngularJs Tab Directive .My Question is How can I move to second tab from first tab with click of a button?Thanks
<tabs>
<pane title="First Tab">
<button type="button" ng-click="moveToSecondTab()">Second Tab.</button>
</pane>
<pane title="Second Tab">
<div>This is the content of the second tab.</div>
</pane>
推荐答案
不要在 HTML 文件中对窗格进行硬编码,而是从控制器中获取它.类似的东西
Instead of hardcoding the panes in your HTML file, fetch it from your controller. Something like
$scope.tabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
];
然后从您的 HTML 中您可以调用该函数来切换活动选项卡.像这样:
Then from your HTML you can call the function to switch the active tab. Something like this :
$scope.moveToSecondTab = function () {
$scope.tabs[1].active = true;
};
但是,如果不是功能,而是直接从按钮切换活动选项卡会更好.
However, it'll be better if instead of a function, you switch the active tab directly from the button.
使用这样的东西:
.
检查此处以供参考.
这篇关于使用angularjs选项卡指令时如何通过单击按钮移动到第二个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文