1

So my HTML is:

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

My router config in 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"
        })
});

I have an error which console throw

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?

vusan
  • 5,221
  • 4
  • 46
  • 81
user2971752
  • 107
  • 1
  • 8

1 Answers1

2

The syntax to send parameter is like a function - enclosed them in braces test({..})

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

Similar issue: Dynamically constructed ui-sref attribute in ui-router

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Great if that helped: here is a link to documentation http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref – Radim Köhler May 15 '14 at 11:50