【问题标题】:Nested views with dot notation带有点符号的嵌套视图
【发布时间】:2017-10-09 15:44:19
【问题描述】:

有人可以帮助我处理 Angular js 中的嵌套视图吗? 我使用这个点符号

  $stateProvider
  .state('contacts/:id', {
  templateUrl: 'contacts.html',
  controller: function($scope){
  $scope.contacts = [{ name: 'Alice' },       { name: 'Bob' }];
   }
   })
  .state('contacts/:id.list/:id', {
   templateUrl: 'contacts.list.html'
   });

  function MainCtrl($state){
     $state.transitionTo('contacts/:id.list/:id'       );
  }

在html中我也这样称呼状态变化

<a ui-sref="contacts/{{value.id}}.list/{{value.id}}">get<\a>

但我总是得到

angular.js:12477 错误:无法从状态“contact/:id”解析“contact/2.list/2”

谢谢

编辑:


我做出改变,就像@Maxim Shoustin 回答的那样。现在状态发生了变化,但是当我单击项目时,在子导航中,父 ui-view 完全刷新(子导航和 ui-view)不仅是子
现在我的状态是这样的

.state('client', {
                url: '/client/info/:itemID',
                templateUrl: 'clientInfo.html',
                controller: 'detailControllerClient as vm',
            })
            .state('client.detail', {
                url: '/detail/:itemID',
                templateUrl: 'itemInfoById.html',
                controller: 'detailControllerClient as vm',
            })

html 就在这里。 (infoDisplay.html 是 index.html 中的父视图。下面代码中的这个 ui-view 是子视图(client.detail)) infoDisplay.html

<div class="new_nav col-lg-1 col-md-1 col-sm-2 col-xs-12">
            <table class="table-hover">
                <thead>
                    <tr>
                        <th>item ID</th>
                    </tr>
                </thead>   
                <tbody>
                    <tr ng-repeat="(key, value) in clientDetail">
                        <td><a ui-sref=".detail({'itemID': value.id})">{{value.id}}</a></td>     
                    </tr>   
                </tbody> 
            </table>
        </div>
        <div ui-view></div> 

【问题讨论】:

    标签: angularjs angular-ui-router


    【解决方案1】:

    &lt;a ui-sref="contacts/{{value.id}}.list/{{value.id}}"&gt;get&lt;\a&gt;

    您不能将 id.listid 一起使用,因为 Angular 在模式中确定了重复名称 id。但是id_list 没问题。例如

    ui-sref文档

    状态在哪里:

    .state('contacts', {
        url: '/contacts/:id_list/:id',  
        templateUrl: 'contacts.html'
      })
    

    和 HTML:

    <a ui-sref="contacts({'id_list': value.id, 'id': value.id})" >contacts</a>
    

    Demo Plunker

    【讨论】:

    • 对不起...这是错误的...这是 ui-sref 而不是 ui-state...这里是 url github.com/angular-ui/ui-router/wiki/… vut 中带有点的示例,这对我来说不起作用...
    • @Arter 好吧,这不是你写的。 :) id.list 在你的情况下是参数而不是状态
    • 有道理:) ...您之前的答案是解决方案还是我需要更改其他内容?星期一我回来工作时会试试这个……我会用结果回复你。感谢这个人
    猜你喜欢
    • 2014-06-30
    • 1970-01-01
    • 2020-12-04
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多