ng-repeat使用标签的问题

时间:2015-11-11 08:13:36

标签: angularjs uiview angular-ui-router angularjs-ng-repeat angular-ui-tabset

我在使用标签内的链接时遇到了问题,这些链接会更改视图并替换标签。仅在选项卡中使用ng-repeat但在静态选项卡中不使用时才会出现此问题。

这是主页:

<div  ui-view name="pageContent">
<uib-tabset>
    <uib-tab ng-repeat="tab in tabs" heading="{{tab.name}}"  active="tab.active" ng-click="!tab.disable && load(tab.link,tab.id)">
    </uib-tab>
    <!-- <uib-tab heading="Static title">Static content</uib-tab>
    <uib-tab heading="Static title">Static content 2</uib-tab> <!-- when I use the comment code it works. -->
    </uib-tabset>
    <div>
        <a class="btn btn-link" ui-sref="xxxx.yyyyy" role="button">
            {{$storage.aaaa.bbbbb}}
        </a><!-- this view replace the pageContent -->
    </div>
</div>

错误是:

  

错误:[$ compile:ctreq]无法找到指令'uibTab'所需的控制器'uibTabset'!

提前致谢

2 个答案:

答案 0 :(得分:5)

I sorted out. That's the code.

 <div class="row top-margin" ng-show=" uiRouterState.current.name !='xxxx'">
   <div class="col-md-12">
      <uib-tabset>
         <uib-tab ng-repeat="tab in tabs" heading="{{tab.name}}"  active="tab.active" ng-click="!tab.disable && load(tab.link,tab.id)">
         </uib-tab>
     </uib-tabset>
  </div>
</div>
<div  ui-view name="pageContent">      
 <a class="btn btn-link" ui-sref="xxxx" role="button">
     Link 
 </a><!-- this link replace the "pageContent" with view xxxxx  -->
<div>

I've created a $scope variable in the controller called $scope.uiRouterState = $state, to store the current state.

答案 1 :(得分:0)

以下更清洁的方式:

  

如果你有纯HTML,我正在使用哈巴狗提防(改变)语法。

 uib-tabset(type="tabs")
 uib-tab(ng-repeat="tabs in tabs track by $index" ng-click="$index = !$index" )
  uib-tab-heading
    span {{ tabs.name }}
    div(ng-if="$index === true")
      span {{ content goes here }}