デフォルトのオプションを角度付きの選択に追加しようとしていますが、それを選択すると、間違って消える空白のオプションが追加されます。anglejsにデフォルトオプションを追加します。
このようにng-options
を使用して選択にバインドするオブジェクトを取得しています。私はこのようなデフォルトのオプションを追加しています:
var DocumentSearchController = function (documentsService) {
documentsService.getDocTypes().then(function (results) {
this.documentTypes = results.data;
this.documentTypes.unshift({ DocumentTypeID: null, Name: 'Select a Document Type' });
}.bind(this));
オブジェクトの構造は次のとおりです。
[{DocumentTypeID: 1, Name: 'Blah'}]
私は、オブジェクトをバインドするng-options
を使用します。
<select class="form-control"
id="documentTypeSelector"
name="documentTypeSelector"
ng-model="vm.selectedDocumentType"
ng-options="option.Name for option in vm.documentTypes | orderBy: 'option.DocumentTypeID':false track by option.DocumentTypeID">
</select>
次にいらいらこれは私が項目を選択したときに削除される空白のオプションが不思議に追加されていることを示します。
オプションも注文されていないので、私のリストの理解は間違っていると思われます。