如何使用ui-router创建json数据的动态链接/视图?

时间:2014-12-09 22:56:31

标签: angularjs angular-ui-router

我希望这项工作:

$stateProvider
  .state('view', {
    abstract: true,
    templateUrl:'../views/view.html',
    controller:'ViewCtrl',
    url:'/view/{index}'
  })


<tr ng-repeat="person in people">
   <td>
      <a href="/#/view/{{$index}}">{{person.fname + ' ' + person.lname}}</a>
    </td>
</tr>

enter image description here

2 个答案:

答案 0 :(得分:0)

模块配置:

  .state('view', {
    templateUrl:'../views/view.html',
    controller:'ViewCtrl',
    url:'/view/{id:[0-9]{1,8}}'
  })

HTML:

<td>    
  <a ui-sref="view({id:{{person.id}}})">{{person.fname + ' ' + person.lname}}</a> 
</td>

..现在可以使用,但我现在可以在视图页面上#t; {t获取$routeParams

答案 1 :(得分:0)

直接在ui-sref中编写表达式,而不在person.id周围使用双括号。

<a ui-sref="view({id: person.id})">{{person.fname + ' ' + person.lname}}</a>