0

This is my combo box:

<select  data-ng-model="data.selectedChannel" 
data-ng-options="salesChannel.value for salesChannel in salesChannels">
</select>

on my controller I have a function which calls a factory that goes away and get a key via web service for example say the key is called "HIRE". My combo box has a few options and one of them has the key of "HIRE".

Now in my controller how do I set the key so that my combo selects that option?

I thought it would be something like this:

$scope.data.selectedChannel.key = "HIRE";

But that doesnt seem to work.

enter image description here

1
  • I don't think this is duplicate, I wanted someone to point our where the problem was in my code. Commented May 9, 2017 at 7:45

1 Answer 1

0

try this Way

for(var i=0;i<$scope.data.selectedChannel.length;i++)
{
  if($scope.data.selectedChannel[i].key=='HIRE')
  {
    $scope.data.selectedChannel = $scope.data.selectedChannel[i];
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your reply, but the => gives me a "syntax error on token ">", delete this token" error (using eclipse). And if i remove that I get an "ReferenceError: f is not defined" on my console (on my browser).
I have update the answer
Still no luck :( Nothing seems to happen.
I did a break point on the for loop, and the .length shows as undefined
problem fixed changing this worked: data-ng-options="salesChannel.key as salesChannel.value for salesChannel in salesChannels"> and then setting $scope.data.selectedChannel = "HIRE";

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.