AngularJS UI-router 如何将状态视图加载到顶层状态的另一个嵌套视图中?

AngularJS UI-router How to load a state view into another nested view of a top level state?(AngularJS UI-router 如何将状态视图加载到顶层状态的另一个嵌套视图中?)
本文介绍了AngularJS UI-router 如何将状态视图加载到顶层状态的另一个嵌套视图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 container 的顶级状态,它包含命名视图 dashboardfeed.

dashboard 视图模板里面我有一个 <div ui-view="tickers"></div> 我想加载tickers 状态,我该怎么做?

I have a top level state called container which holds the named views dashboard and feed.

这是通过在命名视图 dashboard@container 中添加一些东西来完成的吗?

Inside of the dashboard view template I have a <div ui-view="tickers"></div> in there I want to load the tickers state, how would I do that?

容器模板



TheContainertemplate

<div class="fl w100"><em>容器状态</em></div><div ui-view="dashboard" class="fl"></div><div ui-view="feed" class="fl"></div></div>

<div> <div class="fl w100"> <em>Container state</em> </div> <div ui-view="dashboard" class="fl"></div> <div ui-view="feed" class="fl"></div> </div>

仪表板模板

<div class="dashboard-state">
  <em>Dashbaord state</em>
  <div ui-view="tickers"></div>
</div>

代码模块

// Tickers module
var tickers = angular.module('tickers', ['ui.router'])

tickers.config(function($stateProvider) {

  const tickers = {
    parent: 'dashboard',
    name: 'tickers',
    url: '/tickers',
    params: {
      ticker: {}
    },
    views: {
      '': {
        templateUrl: 'tickers-template.html',
        controller: function($scope, $state) {
          console.log('TICKERS view $state');

          $scope.tickers = [
            { id: 1, ticker: 'AAPL' },
            { id: 2, ticker: 'GOOG' },
            { id: 3, ticker: 'TWTR' }
          ];

          $scope.clickTicker = function(ticker) {
            console.log('ticker', ticker)
            $state.go('tags', { ticker: ticker });
          }
        }
      },
      'tags@tickers': {
        templateUrl: 'tags-template.html',
        controller: function($scope) {
          console.log('TAGS view $state');
        }
      }
    }
  }

  $stateProvider.state(tickers);
})

ticksApp主模块

// TickersApp module
////////////////////////////////////////////////////////////////////////////////
var tickersApp = angular.module('tickersApp', ['ui.router', 'container', 'tickers']);

tickersApp.config(function($stateProvider, $urlRouterProvider) {

  $urlRouterProvider.otherwise('/login');

  const login = {
    name: 'login',
    url: '/login',
    templateUrl: 'login-template.html',
    bindToController: true,
    controllerAs: 'l',
    controller: function($state) {
      this.login = function() {
        $state.go('container', { });
      }
    }
  }

  $stateProvider
    .state(login);
});

推荐答案

仍在等待更多答案,但到目前为止,我通过在 dashboard 中使用 tickers.component 得到了这个工作-template.html

Still waiting on more answers, but I got this working so far by using a tickers.component inside of the dashboard-template.html

https://plnkr.co/edit/6dLIk1vq6M1Dsgy8Y4Zk?p=preview

<div class="dashboard-state">
  <div class="fl w100">
    <em>Dashbaord state</em>  
  </div>

  <!--<div ui-view="tickers"></div>-->
  <tickers-module></tickers-module>
</div>

<小时>

tickers.component('tickersModule', {
  templateUrl: 'tickers-template.html',
  controller: function($scope, $state) {
    console.log('TICKERS component');
    $scope.tickers = [
      { id: 1, ticker: 'AAPL' },
      { id: 2, ticker: 'GOOG' },
      { id: 3, ticker: 'TWTR' }
    ];

    $scope.clickTicker = function(ticker) {
      console.log(' Ticker clicked!', $state)
      $state.go('tags', { ticker: ticker });
    }
  }
});

这篇关于AngularJS UI-router 如何将状态视图加载到顶层状态的另一个嵌套视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to sort a array of object based on two properties and check the rage is sequential?(如何根据两个属性对对象数组进行排序,并检查范围是否连续?)
Untyped function calls may not accept type arguments - Angular 5 http calls(非类型化函数调用可能不接受类型参数-角度5 http调用)
ReferenceError: Excel is not defined(ReferenceError:未定义Excel)
How to save two canvas(outer and inner) as png using fabric js in angular(如何保存两个画布(外部和内部)为PNG使用织物js的角度)
Access to #39;Set-Cookies#39; header in $http(访问$http中的Set-Cookies标头)
Adding lt;stronggt;/bold text in translated string using angular-translate(使用角度翻译在翻译后的字符串中添加lt;stronggt;/粗体文本)