微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs中的选项卡与UI-Router和UI-bootstrap无法正常工作

我正在使用MEAN.js样板文件,你可以找到整个代码 here.

我尝试在从列表中选择其中一篇文章后向页面添加2个新选项卡.
为此,我决定为Angular.js使用UI-Router和UI-Bootstrap.
2个选项卡无法正常工作,我可以在它们之间切换并正确查看其内容,但偶尔当我返回并选择文章列表菜单项时,我得到一个带有2个选项卡的空白页面,而不是其他任何内容.

以下是对view-article.client.view.html文件的更改,包括2个新选项卡(之前的内容已复制到包含新选项卡的部分的2个文件中):

<div ng-controller="ArticlesController">
   <tabset>
     <tab
            ng-repeat="t in tabs"
            heading="{{t.heading}}"
            select="go(t.route)"
            active="t.active">
     </tab>
   </tabset>
  <div ui-view></div>
 </div>

我已经在文章控制器中插入了以下几行代码

$scope.tabs = [
       { heading: 'SubA',route:'viewArticle.SubA',active:false },{ heading: 'SubB',route:'viewArticle.SubB',active:false }

   ];

   $scope.go = function(route){
       $state.go(route);
   };

   $scope.active = function(route){
       return $state.is(route);
   };

   $scope.$on('$stateChangeSuccess',function() {
       $scope.tabs.forEach(function(tab) {
           tab.active = $scope.active(tab.route);
       });
   });

这是route.js

'use strict'
angular.module('articles').config(['$stateProvider',function($stateProvider) {
    $stateProvider.
    state('listArticles',{
        url: '/articles',templateUrl: 'modules/articles/views/list-articles.client.view.html'
    }).
    state('createArticle',{
        url: '/articles/create',templateUrl: 'modules/articles/views/create-article.client.view.html'
    }).
    state('viewArticle',{
        url: '/articles/:articleId',templateUrl: 'modules/articles/views/view-article.client.view.html'
    }).
    state('editArticle',{
        url: '/articles/:articleId/edit',templateUrl: 'modules/articles/views/edit-article.client.view.html'
    }).
    state('viewArticle.SubA',{
        url: '/SubA',templateUrl: 'modules/articles/views/view-article.client.view.SubA.html'
    }).

    state('viewArticle.SubB',{
        url: '/SubB',templateUrl: 'modules/articles/views/view-article.client.view.SubB.html'
    });
   }
]);
这与angular-ui bootstrap tab指令和select()回调有关.看起来,当离开tab2时,正在调用tab2中的select()回调.

我变了:

`<tab  ng-repeat="t in tabs"  heading="{{t.heading}}" select="go(t.route)" active="t.active"> `</tab>

至:

`<tab  ng-repeat="t in tabs"  heading="{{t.heading}}"  ui-sref="{{t.route}}" active="t.active"> </tab>`

你的演示现在正常工作.

http://plnkr.co/edit/efnfjoQ8Hft6AZITCR67?p=preview

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐