简体   繁体   English

ui路由器角度主视图

[英]ui-router angular master detail view

I'm trying to get the userlist [master] and user details[detail] on the same page. 我正在尝试在同一页面上获得用户列表[master]和用户详细信息[detail]。

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

module and configuration. 模块和配置。

var myModule = angular.module("myApp", ['ui.router']);  

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

  $stateProvider
  .state('user', {
      url : '/users',
      templateUrl:'users.html',
      controller : 'usersController'
  })
  .state('user.details', {
      url : '/:id',
      templateUrl:'users.html',
      controller : 'usersControllerDetail'
  });

  $urlRouterProvider.otherwise("/users");

});


myModule.controller('usersController' ,  function($scope){
  $scope.users = [{username : 'manish', id : 1}, { username : 'kaustubh', id :2} ]
});

myModule.controller('usersControllerDetail' ,  function($scope, $stateParams){
  console.log($stateParams.id);
});

when ever I click on the user in the master list , master list is rendered twice on scree. 每当我单击母版列表中的用户时,母版列表都会在scree上呈现两次。

can you please let me know where I'm going wrong 你能让我知道我要去哪里了吗

There is adjusted and working plunker 有调整和工作的punker

Just use different template for a child 只是为孩子使用不同的模板

.state('user.details', {
      url : '/:id',
      //templateUrl:'users.html',
      templateUrl:'details.html',
      controller : 'usersControllerDetail'
});

this could be the template 这可能是模板

<div>

 <div ui-view>
  <h3>current state name: <var>{{$state.current.name}}</var></h3>


  <h5>params</h5>
  <pre>{{$stateParams | json}}</pre>
  <h5>state</h5>
  <pre>{{$state.current | json}}</pre>

 </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM