0

I have a select menu.

<select id="dd" ng-show='data != null' ng-model='search'></select>

I triggered the filter to USA as default

$scope.search = 'United States of America';

So far the filter seem to work, but none of my jQuery seem to work.

$scope.search = 'United States of America';
$("#dd").val('United States of America');
$("#dd").attr("selected","selected");

You may see what I have here : JSFiddle


Result now :

enter image description here

Result I want it to be :

enter image description here

What else I should look into to debug this further ?

1
  • I am using Chrome. Commented Mar 7, 2017 at 21:53

1 Answer 1

2

I would do like this-

In your angular controller

$scope.timeFrames = [{ "id": 1, "name": "USA" }, { "id": 2, "name": "UK" }, { "id": 3, "name": "China" }];
$scope.selectedTimeFrame = 1;

In you html page

 <select ng-model="selectedTimeFrame" ng-change="frame()" ng-options="timeFrame.id as timeFrame.name for timeFrame in timeFrames" ng-cloak></select>

Trying to control the select drop down through java script is not the correct way to do. In angular, we have ng-options, Please refer to this documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please update your answer and explain in details a little bit ?
Please refer to this documentation about ng-options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.