Angularjs bootstrap UI添加动态选项卡和页面未加载

时间:2016-04-30 16:38:13

标签: jquery angularjs twitter-bootstrap angularjs-bootstrap

  1. 我添加了动态标签
  2. 点击未加载页面的“创建项目”按钮
  3. 点击“创建作业”按钮后,第二页加载
  4. 点击“项目”标签后,页面打开

    如何打开带有活动的选项卡并动态加载内容。
  5. HTML

            <div class="btn-group btn-group-sm" role="group" aria-label="...">
            <a ng-click="createItem()" class="btn btn-primary ">Create Project</a>   
          </div>
          <div class="btn-group btn-group-sm" role="group" aria-label="...">
            <a ng-click="createJob()" class="btn btn-primary ">Create Job</a>   
          </div> 
             <uib-tabset active="activeTab">
                    <uib-tab index="$index + 1" ng-repeat="tab in tabs" select='getContent($index)' heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
                   <div bind-unsafe-html="tab.content"></div>
                </uib-tab>
           </uib-tabset>
    

    JS

          $scope.activeTab = 0;
    
          $scope.tabs = [
            { tabID : 1, title:'Page A', template: 'a.html',  content:'' , loaded : false, parentTabID:0, active : false },
            { tabID : 2, title:'Page B', template: 'b.html',  content:'', loaded : false, parentTabID:0, active : false },
            { tabID : 3, title:'Page C', template: 'c.html', content:'', loaded : false, parentTabID:0, active : true }
          ];
    
          angular.forEach( $scope.tabs, function(obj, value){
          if (obj.active){
            $scope.activeTab = value+1;    
            }
          });
    
          $scope.createItem = function () {
            var ta = false;
            angular.forEach( $scope.tabs, function (key) {
              if(key.tabID == 4){
            ta = true;
              }
            });
    
            if(ta){
              return false;
            }
    
            var menu = {
              title: "Project",
              template: "d.html",
              active: true,
              loaded: false,
              tabID: 4,
              content: "",
              parentTabID: 2
            };
            $scope.tabs.push(menu);
            setIndex(4);
          };
    
          $scope.createJob = function () {
    
            var ta = false;
            angular.forEach( $scope.tabs, function (key) {
              if(key.tabID == 5){
            ta = true;
              }
            });
    
            if(ta){
              return false;
            }    
    
            var menu = {
              title: "Job",
              template: "e.html",
              active: true,
              loaded: false,
              tabID: 5,
              content: "",
              parentTabID: 2
            };
            $scope.tabs.push(menu);
            setIndex(5);
          };  
    
        $scope.getContent = function (index) {
           var item = [];
    
            angular.forEach($scope.tabs, function (key, value) {
              if(value === index){
            item.push(key)
              }
            });
    
            /* or make request for data delayed to show Loading... */
            $timeout(function () {
              $http.get(item[0].template).then(function (res) {
            item[0].content = res.data;
            item[0].loaded = true;
              });
            }, 100);
          };
    
          function setIndex(tabID) {  
    
          // all active to false
            angular.forEach( $scope.tabs, function (key) {
              key.active = false;
            });
    
            // new tab going to active 
            angular.forEach( $scope.tabs, function(obj, value){
            if ( obj.tabID == tabID){
              obj.active = true;   
              $scope.activeTab = tabID; 
              }
            });
            }         
    

    Here the my sample code

0 个答案:

没有答案