AngularJS UI-router How to load a state view into another nested view of a top level state?

后端 未结 2 1064
醉酒成梦
醉酒成梦 2020-12-22 03:12

https://plnkr.co/edit/XnDUIqfVuBS2Hr2N1ooy?p=preview

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

相关标签:
2条回答
  • 2020-12-22 03:57

    I think you should use different states on the container like these:

    $stateProvider .state('container', { url: '/container', templateUrl: '' })

        .state('container.feed', {
            url: '/container/feed',
            templateUrl: 'partial-home.html'
        })
    
        .state('container.dashboard', {
            url: '/container,
            templateUrl: 'partial-home.html'
        })
    

    And use ui-sref

    0 讨论(0)
  • 2020-12-22 04:16

    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 });
        }
      }
    });
    
    0 讨论(0)
提交回复
热议问题