Reputation: 85
I am getting the URL as below with ${USERID}
and I just want to replace with a.userId javascript object value.
angular.forEach(users.items, function(a))
{
//navigationUrl="mysite.com/users/userId=${USERID}
link = $scope.navigationUrl + a.userId
}
In the above code, I just need to replace the navigationUrl's ${USERID} with a.userId. How do I achieve this?
Upvotes: 0
Views: 821
Reputation: 75650
I have a hunch you're trying to use angular incorrectly. Forgive me if my hunch is incorrect.
Looks like you want to generate a list of links based on an array of users. Try this...
angular.module("demo", [])
.controller("userController", function($scope) {
$scope.users = [
{ name: "bob", userId: 1234 },
{ name: "jane", userId: 5678 }
];
});
<div ng-app="demo" ng-controller="userController">
<ul>
<li ng-repeat="user in users">
<a ng-href="mysite.com/users/userId={{user.userId}}">{{user.name}}</a>
</li>
</ul>
</div>
See a working demo
Upvotes: 1
Reputation: 1215
Something like:
angular.forEach(users.items, function(a))
{
//navigationUrl="mysite.com/users/userId=${USERID}
link = $scope.navigationUrl.replace("${USERID}", a.userId);
}
assuming that your user id is 16
you will have mysite.com/users/userId=16
Upvotes: 2