我想在angularJs中選擇一個下拉值並將其保存在服務中,這樣我就可以在另一個視圖上使用它來顯示用戶所選的值和完整的下拉列表。但是,當我嘗試在controller中記錄選定的值。我正在獲取undefined的值。請幫助我如何繼續。Angular Js dropdown所選值控制器內未定義
<td>
<select name="systems" class="pulldown1" id="systems" ng-model="system.selectedOption" ng-controller="EurexController" required ng-options="option.name for option in system.availableOptions track by option.id" ng-init="system.selectedOption=system.availableOptions[0]" ng-change="changed()"> </select>
</td>
控制器代碼:
$scope.system = {
availableOptions: [{
id: 'Domestic 1',
name: 'Domestic 1'
}, {
id: 'Domestic 2',
name: 'Domestic 2'
}, {
id: 'Global',
name: 'Global'
}, {
id: 'Far East',
name: 'Far East'
}],
// selectedOption: {id: 'Domestic 1', name: 'Domestic 1'} //This sets the default value of the select in the ui
};
我使用AngularJS網站。但是提到selectedoption也嘗試仍然不可能做到這一點。
console.log($scope.system.selectedOption);
console.log(systems);
這是一個有效的問題,我得到了我的答案。有人可能會說爲什麼這是低調的? – Praveen