简体   繁体   English

uib-tabset指令有条件地加载

[英]uib-tabset directive load conditionally

I have a uib-tabset as below. 我有一个uib标签集,如下所示。

<uib-tabset active="activeJustified" justified="true">
    <uib-tab index="0" heading="Address" >
        <by-adr></by-adr>

    </uib-tab>
    <uib-tab index="1" heading="country" >
       <by-country></by-country>
    </uib-tab>

When the page loads my Database call inside the controller of both the directives are called instead I want to call the controller inside directive to be called only when the tab is selected.can Some body help me in this.when country tab is selected then I should call Database call in by-country directive.Instead of loading all at one time.I am using angularJS 1.x 当页面将我的数据库调用都加载到两个指令的控制器内部时,我想只在选择选项卡时才调用控制器内部的指令。可以在此使用某些主体。当选择了国家/地区选项卡时,我应该在by-country指令中调用数据库调用,而不是一次全部加载。我正在使用angularJS 1.x

I am trying to Load the directive only when the tab is selected.Example when I click country tab then I want my by-country directive to load. 我仅在选择选项卡时才尝试加载指令,例如在单击``国家/地区''选项卡后希望按国家加载指令

I don't know your full code but you can do following: 我不知道您的完整代码,但是您可以执行以下操作:

$broadcast $广播

once you loaded data from database, you can fire event to your directives (suppose they are loaded already) 从数据库加载数据后,就可以向指令触发事件(假设它们已经加载)

In root controller: 在根控制器中:

$rootScope.$broadcast('onDBLoaded', {});

and in directive controller: 并在指令控制器中:

$scope.$on("onDBLoaded", function() {
   run();  // run your main logic
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM