【问题标题】:Make angularJS ui router work with angular material design TABS使 angularJS ui 路由器与 Angular Material Design TABS 一起工作
【发布时间】:2015-08-05 14:21:08
【问题描述】:

当应用启动时 TabControl 是可见的,但是...

当我点击一个标签时,没有内容可见

我做错了什么?

我使用最新的 angularJS 材料设计 0.9.4。

   $urlRouterProvider.otherwise("");
      $stateProvider

          .state("main",
          {
            abtract: true,
            url: '',
            views: {
              'content@': {
                templateUrl: '../app/views/administration/administration.html',
                controller: 'AdministrationController'
              }
            }
          })
          .state('main.settings', {
            url: '/settings',
            views: {
              'settings@main': {
                templateUrl: "../app/views/administration/settings.html",
                controller: 'GlobalConfigurationController'
              }
            }
          })
          .state('main.schoolyears', {
            url: '/schoolyears',
            views: {
              'schoolyears@main': {
                templateUrl: "../app/views/schoolyear/schoolyears.html",
                controller: 'SchoolyearsController'
              }
            }
          });

HTML

<div layout-fill layout="column">
  <div ng-include="'app/components/navbar/navbar.html'"></div>
  <div id="content" layout="column" layout-padding>

    <md-tabs md-stretch-tabs="always" class="md-primary md-hue-2">

      <md-tab label="Schoolyears" ui-sref="main.schoolyears" md-active="$state.is('main.schoolyears')">
        <md-tab-body ui-view="schoolyears" layout="vertical" layout-fill></md-tab-body>
      </md-tab>

      <md-tab label="settings" ui-sref="main.settings" md-active="$state.is('main.settings')">
         <md-tab-body ui-view="settings" layout="vertical" layout-fill></md-tab-body>
      </md-tab>

    </md-tabs>
  </div>
</div>

【问题讨论】:

  • 你能把代码发布到你用
  • 您想要控制器代码吗?或者知道我是否将控制器包含在 index.html 中?
  • 我在浏览器控制台中没有错误。因此,所有文件都包括在内。所有 3 个控制器都是空的,没有我的代码。他们也不需要代码来使选项卡工作。这只是一个路由器/状态和 html 问题。
  • 好的。在这种情况下,当您单击 schoolyears 选项卡时,您能否判断 schoolyears,html 是否被调用?通过控制台?
  • 控制台没有输出。

标签: angularjs angular-ui-router material-design


【解决方案1】:

更新:在 Angular Material 0.10.0 中修复了 ui-srefmd-tabs 的使用

解决方法已发布在 github 上,previous known md-tab issue

有一个带有解决方法的plunker(它似乎在没有视图的情况下工作):

  $stateProvider
      .state('tabs', {
        abstract: true,
        url: '/tabs',
        templateUrl: 'tabs.html',
        onEnter: function() { console.log("enter tabs.html"); } })

      .state('tabs.tab1', {
        url: '/tab1',
        onEnter: function() { console.log("enter tab1.html"); },
        controller: function($scope) {

        },
        templateUrl: 'tab1.html'
      })
      .state('tabs.tab2', {
        url: '/tab2',
        onEnter: function() { console.log("enter tab2"); },
        controller: function($scope) {

        },
        templateUrl: 'tab2.html'
      });

【讨论】:

  • 我知道这是一个问题,但我注意到 Your Plunker 中仍然存在一个错误。当您在浏览器选项卡中点击返回箭头时,内容从tab 2 更改为tab 1 但仍选择tab 2(当内容显示tab 1 时,tab 2 下方有红线)。这可以解决吗?
  • 请不要再使用那个pl​​unker了。它是用旧版本的 Angular Material 制作的,需要解决方法才能与 ui-router 配合使用。现在已经不是这样了。
  • 你可以在没有“span”的情况下看到它工作正常:plnkr.co/edit/psinbetM1CUBqIxuL1yq
  • 感谢您的回复,但在您最新的 Plunker 中单击浏览器中的 back tab 1 时未被选中。我稍微调整了你的代码,得到了这个:plnkr.co/edit/4gKaghePnTMh4NgfQcxC?p=preview
  • 无论如何感谢您的回答,您的代码帮助我入门
猜你喜欢
  • 2015-08-13
  • 1970-01-01
  • 2016-12-08
  • 2016-07-09
  • 2018-04-04
  • 2013-11-05
  • 2016-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多