Try to render two templates in same View (Ui-Router)

折月煮酒 提交于 2019-12-11 17:35:08

问题


I'm trying to render two templates at the same time in same View using two differents ui-view. I'm probably missing something but I don't know what. Can I get some help ?

My App.js

var routerApp = angular.module('routerApp', ['ui.router']);

routerApp.config(function($stateProvider) {

  //$urlRouterProvider.otherwise('/home');

  var People = {
    name: 'People',
    url: '/People',
    views: {
      'PeopleView': {
        templateUrl: 'People.html'
      }
    }

  }

  var Company = {
    name: 'Company',
    url: '/Company',
    views: {
      'CompanyView': {
        templateUrl: 'Company.html'
      }
    }
  }

  $stateProvider.state(People);
  $stateProvider.state(Company);
});

HTML

<div class="container">
  <fieldset>
    <div class="row">
      <legend>Content</legend>
      <div ui-view="PeopleView" class="col col-md-4"></div>
      <div ui-view="CompanyView" class="col col-md-4"></div>
    </div>
  </fieldset>
</div>

Full Code


回答1:


I'm not quite sure what you need to achieve, but I guess that you should put both your views into the same state and work on within it

$stateProvider.state('mainState', {
    views: {
      'CompanyView': {
        templateUrl: 'Company.html'
      },
      'PeopleView': {
        templateUrl: 'People.html'
      }
    }
})

I've edited your plunk to illustrate what I mean - http://plnkr.co/edit/V0lF78MZhrOnwXF7F6Ih?p=preview



来源:https://stackoverflow.com/questions/46268849/try-to-render-two-templates-in-same-view-ui-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!