angular - ng-option 未从异步调用更新
问题描述
我有一个从异步调用加载的选择元素的选项列表。调用已成功执行,但选择未更新...
html
<select ng-model="selectedCommand"
ng-options="command as command.name group by command.group for command in commands" >
<option value="">-- Please select --</option>
</select>
home.component.ts
populateCommands(context, dataService) {
dataService.getCommands()
.do(console.log)
.mergeMap(Observable.from)
.mergeMap(group => {
return Observable.from(group.commands)
.map(command => {
command.group = group.name;
return command;
})
}).pipe(toArray())
.subscribe(commands => {
console.log(commands);
context.commands = commands;
});
}
ngOnInit() {
var dataService = this.dataService;
var populateCommands = this.populateCommands;
var context = this;
this.data.getLoggedInUser()
.do(function() { populateCommands(context, dataService);})
.subscribe(user => {
this.loggedInUser = user;
})
}
有没有办法通过 ng-options 更新选择?
以下作品:
<select #command="ngModel" required class="custom-select geant-text-small"
[(ngModel)]="selectedCommand" name="command"
(click)="onTouched()">
<option value="">-- Select Command --</option>
<optgroup label="{{group.name}}" *ngFor="let group of commandGroups$">
<option [ngValue]="command" *ngFor="let command of group.commands">
{{command.name}}
</option>
</optgroup>
</select>
解决方案
推荐阅读
- java - 如何更改字符串中单词的位置(对称)
- java - 如何使用 Java ProcessBuilder 自动化命令行脚本
- sql-server - 除了部分用户使用 Kaspersky Endpoint Security 10 外,如何限制远程用户连接 SQL Server 数据库?
- symfony - 如何为 Symfony 实体类制作自定义 JSON 解码器?
- java - selenium-jupiter - 连接到 seleniumGrid 的 testTemplates
- node.js - 无法通过节点 sdk 验证 aws iot 订阅
- r - 按行和名称将单个向量元素分配给单个列 - r
- jquery - 使用 jQuery 对嵌套的剑道甜甜圈图进行爆炸和标注
- azure - 连接到 LDAP 服务器时出错 - jFrog Artifactory 与 Azure LDAPS 集成
- javascript - 当我使用 jquery AJAX 函数将参数解析为 asp.net 代码时调用的错误函数