When attempting to pass a variable to a page, the URL I'm using is:
http://localhost/project/#/app/intro/1
After routing to my controller, everything seems fine until I try to use the map
function on an array in my controller - that's where the problem arises!
The code in question looks like this:
console.log($stateParams.userId); // returns 1
var ePos = $rootScope.data.users.map(function (x) {
return x.id;
}).indexOf($stateParams.userId);
console.log(ePos); // returns -1
Interestingly, when I switch to using static data instead of the variable, everything works as expected:
console.log($stateParams.userId); // returns 1
var ePos = $rootScope.data.users.map(function (x) {
return x.id;
}).indexOf(1);
console.log(ePos); // returns 0