私は、ユーザーがGoogleマップを使用して目的地へのルートを取得するためのフォームを用意しています。 ユーザーが選択できる設定可能な宛先は350あります。彼らは、Googleマップ上のピンをクリックするか、またはフォーム内の選択メニューからこの目的地を選ぶことができます。ng-ng-optionsまたはng-repeatで動作していません
Googleマップのピンをクリックすると、選択メニューが目的地に変更されます。
これはng-selectedを使用しようとしていますが、動作しません。
何か助けが大歓迎です。ありがとうございました。
ビュー
<div id="select_destination">
<select data-ng-model="selectedDestination"
ng-options="station.stationID as station.stationShortAddress for station in allStationsMapData track by station.stationID"
data-ng-change="selectDestination(selectedDestination)"
ng-selected="station.stationID == selectedDestination">
</select>
</div>
コントローラ
ユーザーは、地図上の駅をクリックしたときにgetDirections呼び出される関数は、(選択メニューからの選択ではない)と呼ばれています。これにより、選択メニューの現在選択されている項目が変更されますが、変更されません。 (注:関数は右stationIDに渡して、正しく実行されている)
$scope.getDirections = function(stationLat, stationLng, stationID){
//update the select menu model to the chosen stationID.
$scope.selectedDestination = stationID;
};
追加情報:
私はまた、しかし、それはどちらか動作しませんでしたNG-繰り返しでNG-選択を使用してみました。
<select data-ng-model="selectedDestination" data-ng-change="selectDestination(selectedDestination)">
<option ng-repeat="stationMapData in allStationsMapData"
value="{{stationMapData.stationID}}"
ng-selected="{{stationMapData.stationID == selectedDestination}}">
{{stationMapData.stationShortAddress}}
</option>
</select>
グレート例感謝。しかし、私はちょうどそれを変更しようとし、まだ動作しません。しかし、少なくとも私は実際の例を見ることができます。私はそれが働くようになるとすぐにあなたに戻ってきます。 – Sarah
私はインデックスベースの配列で(あなたの例のおかげで)働いていますが、配列がオブジェクトの配列である場合には動作しないようです。あなたはそれを試して、あなたがそれを稼働させることができるかどうかを見ることができます。 $ scope.Quarters = {{'ID': 'Q1'}、{'ID': 'Q2'}、{'ID': 'Q3'}、{'ID': 'Q4'}] ; – Sarah
オブジェクトでフィドルを見てください。 https://jsfiddle.net/bjs3g/239 –