I have an object array that contains states. It has three fields (id, name, abbr)
To simplify things, I'll use three states:
states: any = [{
"stateId": 3,
"stateName": "Arizona",
"stateAbbreviation": "AZ"
},
{
"stateId": 4,
"stateName": "Arkansas",
"stateAbbreviation": "AR"
},
{
"stateId": 5,
"stateName": "California",
"stateAbbreviation": "CA"
}]
I have a provider where I want to return an object if it matches the stateId I pass it.
So in my provider I have the following funciton:
getState(stateId){
this.states.forEach(function(element) {
if(element.stateId == stateId){
return element;
}
});
}
In my home controller I simply call it like this:
console.log('State is: ', this.states.getState(50));
But I'm getting the error: undefined.
What am I doing wrong?