2017-03-07 8 views
0

私は選択メニューを持っています。デフォルト値を設定すると、ドロップダウンメニューのテキストが表示されません - AngularJS

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

私はこれまでのところ、デフォルト

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

としてフィルタを米国にフィルタをトリガーが動作するように見えるが、私のjQueryのどれも動作するようには思えません。

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

あなたは私がここに持っているものを見ることがあります。JSFiddle


結果になりました:私はそれになりたい

enter image description here

結果:

enter image description here

さらにこれをデバッグするにはどうすればいいですか?

+0

私はChromeを使用しています。 – ihue

答えて

2

私はJavaスクリプトを下の選択ドロップをコントロールしようとすると、あなたのHTMLページ

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

では、あなたの角度コントローラ

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

ではthis-

のように行うだろうされていません正しいやり方。角度があると、ng-optionsがあります。documentationを参照してください。

+0

あなたの答えを更新して詳細を少し説明してもらえますか? – ihue

+0

ng-optionsについては、この[documentation](https://docs.angularjs.org/api/ng/directive/ngOptions)を参照してください。 – ISHIDA

関連する問題