我是棱角分明的新手
我坚持以下问题
我有一个选择下拉,由AJAX调用填充我的要求是默认选择选项,我知道如何做JQUERY
简而言之请告诉我相当于$(#id).val()的角度 以下是摘录
<select id="eventypeee" ng-change="appendselected()"
ng-model="eventtypelistforcity.selected"
ng-options="option.eventId as option.eventAliasName for option in eventtypelistforcity | orderBy:'eventAliasName'">
<!-- test -->
</select>
我希望选择的eventid = 11被选中
答案 0 :(得分:0)
如果为所选选项创建单独的模型,而不是将其指向用于创建选项的同一对象,则会更容易。试试这个:
<强> HTML 强>
<body ng-controller="MainCtrl">
<select
id="eventypeee"
ng-change="appendselected()"
ng-model="selectedOption"
ng-options="option.eventId as option.eventAliasName for option in eventtypelistforcity | orderBy:'eventAliasName'"
></select>
<pre>{{selectedOption}}</pre>
</body>
<强> JS 强>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.eventtypelistforcity = [
{
eventId: 1,
eventAliasName: 'foo'
},
{
eventId: 2,
eventAliasName: 'bar'
},
{
eventId: 3,
eventAliasName: 'baz'
}
];
// defined a model for your selected option
// you access the selected option through this..
$scope.selectedOption = $scope.eventtypelistforcity[0].eventId;
$scope.appendSelected = function(){
}
});
答案 1 :(得分:0)
您可以像这样简单地使用ngSelected指令:
<select id="eventypeee" ng-change="appendselected()" ng-model="eventtypelistforcity.selected">
<option ng-selected="option.eventId==11" data-ng-repeat="option in eventtypelistforcity" value="{{ option.eventId }}">{{ option.eventAliasName }}</option>
</select>
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.eventtypelistforcity = [
{
eventId: 11,
eventAliasName: 'Event11'
} ,
{
eventId: 1,
eventAliasName: 'foo'
},
{
eventId: 2,
eventAliasName: 'bar'
}
];
//Define your model corresponding to your select value
$scope.eventtypelistforcity.selected $scope.eventtypelistforcity[0].eventId;
});
DEMO:Plunker