Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top