在HTML中填充输入
我面临一个问题,主要是我不能在输入中填充值,而是在HTML中填充值。我搜索了一下,但似乎什么也没找到。我尝试了value、在HTML中填充输入,html,angular,angular11,Html,Angular,Angular11,我面临一个问题,主要是我不能在输入中填充值,而是在HTML中填充值。我搜索了一下,但似乎什么也没找到。我尝试了value、(value)、[(value)]、“k.bag.ConstructionYear”、“{{k.bag.ConstructionYear}}”和其他组合,但似乎没有任何效果 mycomponent.html <ng-container *ngIf="{ // other stuff firstStepState: firstStepStat
(value)
、[(value)]
、“k.bag.ConstructionYear”
、“{{k.bag.ConstructionYear}}”和其他组合,但似乎没有任何效果
mycomponent.html
<ng-container
*ngIf="{
// other stuff
firstStepState: firstStepState$ | async
} as o"
>
//........
<ng-container *ngIf="{
bag : testService.getData(o.firstStepState.value1, o.firstStepState.value2) | async
} as k">
<ng-container *ngIf="k.bag !== undefined && k.bag !== null">
{{k.bag.ConstructionYear}} // <-- this is showing
<input
type="text"
name="constructionYear"
formControlName="constructionYear"
id="constructionYear"
data-test="constructionYear"
placeholder=""
[value]="k.bag.ConstructionYear" <-- this is the problem
/>
//........
{{k.bag.ConstructionYear}/
要通过将formControlName=“constructionYear”
分配给输入来绑定数据,可以将此输入的值控制委托给formControl。从现在开始,您应该随时根据ts代码更新逻辑形式,而不是输入值。例如,通过方法control.setValue(newValue)
不要将被动表单模型与模板表单模型混合使用。i、 e.formControlName
和ngModel
属性不应同时位于同一元素上。
<input
type="text"
name="constructionYear"
formControlName="constructionYear"
id="constructionYear"
data-test="constructionYear"
placeholder=""
[(ngModel)]="k.bag.ConstructionYear"
/>