我有与这里提到的完全相同的问题:如何在 Angular.js 选择框中有一个默认选项
但是,没有一个答案可以解决我的问题,我试图让第一个类别显示在选择中:
<p>Choose a tag category:</p>
<div class="select-style">
<select ng-model="modal.addedTag" ng-init="modal.addedTag = modal.categories[0].name" ng-options="category.name for category in modal.categories">
<!-- <option value="brand" selected>Brand</option>
<option value="client">Client</option>
<option value="company-name">Company Name</option>
<option value="government">Government</option>
<option value="events">Events</option>
<option value="industry">Industry</option>
<option value="products">Products</option>
<option value="news">News</option> -->
</select>
</div>
我的控制器中的模型:
var vm = this;
vm.categories = [
{ name: 'brand' },
{ name: 'client' },
{ name: 'competitor-name' },
{ name: 'company-name' },
{ name: 'government' },
{ name: 'events' },
{ name: 'industry' },
{ name: 'people' },
{ name: 'philanthropic' },
{ name: 'products' },
{ name: 'product-category' },
{ name: 'product-feature' },
{ name: 'place' },
{ name: 'problem' },
{ name: 'news' },
{ name: 'related-company-name' },
{ name: 'trend' }
];