HI尝试使用filter /orderBy选择第一个选项:然而它不起作用,我知道|是angular中的一个过滤函数。当前选择的是最后一个值/标签,如何才能选择第一个标签(天)?
我尝试了orderBy:-npu.label和下面的代码,但没有成功。
vm.NoticePeriodUnitValue = [{
value: 1,
label: 'Days'
}, {
value: 7,
label: 'Weeks'
}, {
value: 30,
label: 'Months'
}, {
value: 365,
label: 'Years'
}];
<select name="NoticePeriodOptions" data-ng-change="vm.setNoticePeriod()" data-ng-model="vm.NoticePeriodUnit"
class="form-control search-input inverted mt-10" id="profile_notice-period-unit"
data-ng-options="npu.value as npu.label for npu in vm.NoticePeriodUnitValue | filter: -npu.label">
</select>发布于 2016-03-29 20:08:44
将这个添加到您的代码中,
vm.NoticePeriodUnit = vm.NoticePeriodUnitValue[0].value; 这将为您提供一个开始时的默认值
发布于 2016-03-29 20:15:55
您可以为模型设置默认值并删除该文件服务器。
$scope.vm = {
NoticePeriodUnitValue: [{
value: 1,
label: 'Days'
}, {
value: 7,
label: 'Weeks'
}, {
value: 30,
label: 'Months'
}, {
value: 365,
label: 'Years'
}],
NoticePeriodUnit: 1
}发布于 2016-03-30 00:00:59
Controller:
vm.NoticePeriodUnitValue = [{
value: 1,
label: 'Days'
}, {
value: 7,
label: 'Weeks'
}, {
value: 30,
label: 'Months'
}, {
value: 365,
label: 'Years'
}];
vm.NoticePeriodUnit = {value: 1, label: 'Days'};
vm.setNoticePeriod = function() {
console.log(vm.NoticePeriodUnit);
}
HTML:
<select name="NoticePeriodOptions" data-ng-change="vm.setNoticePeriod()" data-ng-model="vm.NoticePeriodUnit.value"
class="form-control search-input inverted mt-10" id="profile_notice-period-unit"
data-ng-options="npu.value as npu.label for npu in vm.NoticePeriodUnitValue">
</select>https://stackoverflow.com/questions/36283278
复制相似问题