2014-05-15 125 views
1

所以我的HTML是:角NG-重複錯誤

<div class="checkbox" ng-repeat="test in tests"> 
    <a ui-sref="test{{id: test._id}}"><pre>{{test._id}}</pre></a> 
</div> 

我在app.js路由器配置

myApp.config(function($stateProvider, $urlRouterProvider){ 
    $urlRouterProvider.otherwise(""); 
    $stateProvider 
     .state('main', { 
      url: "" 
     }) 
     .state('new', { 
      url: "/new", 
      templateUrl: "templates/new.html" 
     }) 
     .state('test', { 
      url: "/tests/:id", 
      templateUrl: "templates/test.html" 
     }) 
}); 

我有一個錯誤,控制檯拋出

Error: Syntax Error: Token ':' is an unexpected token at column 3 of the expression [id: test._id] starting at [: test._id]. at Error (native) What the problem?

回答

2

語法發送參數就像一個功能 - 將它們封閉在大括號中test({..})

<div class="checkbox" ng-repeat="test in tests"> 
    <a ui-sref="test({id: test._id})"><pre>{{test._id}}</pre></a> 
</div> 

類似的問題:Dynamically constructed ui-sref attribute in ui-router

+0

你吧,謝謝。 – user2971752

+0

很好,如果有幫助:這是一個鏈接到文檔http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref –