我正在使用带有 select2 插件的 angularjs。
当我编辑具有可以从下拉列表设置它的属性的项目时,当前选择的值在下拉列表中被选择/突出显示但不可见。我必须实际单击下拉菜单才能看到实际选择的选项。基本上起初该字段是空的......
像这样:

如您所见,该字段为空,但如果单击它,您会看到亚利桑那州已被选中。如何在下拉列表中直接显示亚利桑那州而无需单击它?
这就是我将它绑定到元素的方式。
<select data-custom-select class="form-control" data-ng-model="newType.Type" data-ng-options="t for t in definitions.Types"></select>
data-custom-select是一个允许我select2()在元素上应用的指令:
directive('customSelect', [function () {
var link = function (scope, element, attrs) {
element.select2();
};
return {
restrict: 'A',
link: link
};
}])
该模型:
$scope.newType = {
Type: 'Type 1'
}
$scope.definitions ={
"Definitions": [{
"Id": "1",
"Name": "Name 1"
}, {
"Id": "2",
"Name": "Name 2"
}],
"Types": ["Type 1", "Type 2", "Type 3"]
};