Angular 数据库中的记录未绑定到数据库中的Select控件
我有一个带有输入字段和选择控件的编辑表单。这些控件应该由数据库中的一条记录填充。输入字段中有各自的数据,但选择控件没有 这是我的选择控件之一Angular 数据库中的记录未绑定到数据库中的Select控件,angular,Angular,我有一个带有输入字段和选择控件的编辑表单。这些控件应该由数据库中的一条记录填充。输入字段中有各自的数据,但选择控件没有 这是我的选择控件之一 <select id="taxAuthorityId" name="taxAuthorityId" [(ngModel)]="tax.taxAuthorityId" class="form-control"> <option *ngFor="let b of taxAuthorities" value={{b.Id}}>{{b
<select id="taxAuthorityId" name="taxAuthorityId" [(ngModel)]="tax.taxAuthorityId" class="form-control">
<option *ngFor="let b of taxAuthorities" value={{b.Id}}>{{b.name}}</option>
</select>
通常,值属性值会被字符串化,因此当您将
b.id
放入其中时,它会变成'1'
,而不是1
。因此,当涉及到预选值1=='1'时,这个表达式不会得到满足。将value
更改为[ngValue]=“b.Id”
将有助于保留值类型
<select id="taxAuthorityId" name="taxAuthorityId"
[(ngModel)]="tax.taxAuthorityId" class="form-control">
<option *ngFor="let b of taxAuthorities"
[ngValue]="b.Id">
{{b.name}}
</option>
</select>
{{b.name}
你好。它在控制台中抛出了一个解析器错误。整个应用程序没有运行run@KaceyEzerioha你能告诉我什么是错误吗?对不起,是我的错。我用“”替换了{{}},因为你的答案是这样的。但是它仍然没有显示所选的值。我的错误再次出现。财产是错的。它应该是“b.id”而不是“b.id”。你的回答是正确的。非常感谢。我不相信我在这上面花了两个晚上。
<select id="taxAuthorityId" name="taxAuthorityId"
[(ngModel)]="tax.taxAuthorityId" class="form-control">
<option *ngFor="let b of taxAuthorities"
[ngValue]="b.Id">
{{b.name}}
</option>
</select>