我想從數據庫填充選擇下拉列表。現在數據來自範圍數組。自定義指令來填充級聯下拉列表
HTML:
<div ng-controller="DropDownController">
Country:
<select id="country" class="input-sm" name ="country" ng-model="states" ng-options="country for (country, states) in countries" drop-down required>
<option value=''>Select</option>
</select>
States: <select id="state" class="input-sm" name="state" ng-disabled="!states" ng-model="cities" ng-options="state for (state,city) in states" required>
<option value=''>Select</option></select>
City: <select id="city" class="input-sm" name="city" ng-disabled="!cities || !states" ng-model="city" required>
<option value=''>Select</option>
<option ng-repeat="city in cities" value='{{city}}'>{{city}}</option></select>
</div>
指令:
app.directive('DropDown', function ($http) {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
$http.get('DropDown.do').success(function (data) {
if (data) {
}
});
}
};
});
我不知道上面的指令是對我的要求的做法的正確途徑。當我點擊下拉選項時,servlet或url沒有被調用。我如何實現相同?我仍然是一個角度初學者。
我是一點從你的問題感到困惑,做你想用DB中的值填充下拉列表,或者當你點擊任何選項時你想調用servlet url嗎? –
我想填充數據庫中的下拉列表 – kittu