3gwebtrain 3gwebtrain - 23 days ago 7
AngularJS Question

UI-router throw error as `Invalid state ref`, when adding link to `ui-sref'

for the following

route
:

.state('user', {
url:'/user/:userId',
templateUrl : 'app/views/pages/user/user.html',
controller : 'userController as user',
required : true,
resolve : {
userData : function( $q, api, $stateParams ){

console.log('hi', $stateParams)

var differed = $q.defer();

api.getUsers().then(function( data ){
differed.resolve( data.data );
});

return differed.promise;

}
}
})


I am calling from one of my html as like this:

<li ng-repeat="user in users.usersData"><a ui-sref="user(userId:{user._id})">{{user.name}}</a></li>


But getting error as :

angular.js:13920 Error: [$parse:syntax]

https://docs.angularjs.org/error/$parse/syntax?p0=:&p1=is%20an%20unexpected%20token&p2=7&p3=userId:%7Buser._id%7D&p4=:%7Buser._id%7D


what is wrong with my code? any one help me here?

Answer

The ui-sref

ui-sref="user(userId:{user._id})"

should be like

ui-sref="user({userId:user._id})"

what we pass is an object with property named userId and value coming from user._id: {userId:user._id}