- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试加载一组已保存的模板,以便能够从它们中选择作为 ionic 选择中的选项,并根据选择的选项更新表单。
这就是我的模板的组成方式:
export interface Template {
...
destination: string; //iban
recipient: string;
amount: number;
reference: string;
}
这就是我的 ionic 选择的样子:
<ion-item>
<ion-label>Load template</ion-label>
<ion-select (change)="this.transactionForm.patchValue({recipient: template.recipient, destination: template.destination, amount: template.amount, reference: template.reference})">
<ion-option *ngFor = "let template of templates;">
{{template.reference}}
</ion-option>
</ion-select>
</ion-item>
我们的想法是加载已保存的模板并在列表中选择一个模板,以便在您做出选择后我正在填写的表单中的值会得到更新。
这是我在 .ts 文件的构造函数中初始化表单的方法:
constructor( public formBuilder: FormBuilder, public templateServicerino: TemplateService) {
this.templateServicerino.createTemplate("DE365849", "John Johnson", 420, "Testerino");
this.templates = this.templateServicerino.getAllTemplates();
this.transactionForm = this.formBuilder.group({
recipient: [''],
destination: [''],
amount: ['0'],
reference: ['']
});
当我对此进行测试时,当我单击选择时,我确实得到了一个名为“Testerino”的选项,但是一旦我按“确定”,表单就不会更新。我的 IDE 说字段"template"未解析
预先感谢您的帮助
最佳答案
您试图访问元素范围之外的模板引用。更改方法不是 ionic 方法。因此请参阅此链接 https://github.com/ionic-team/ionic/issues/7807
更多引用检查 ionic 文档:https://ionicframework.com/docs/api/components/select/Select/
<ion-item>
<ion-label>Load template</ion-label>
<ion-select [(ngModel)]="selectObj" (ionChange)="onSelectChange($event,selectObj)"
>
<ion-option *ngFor = "let template of templates;">
{{template.reference}}
</ion-option>
</ion-select>
</ion-item>
构造函数方法之后组件中的过去代码。
onSelectChange(selected:any,selectObj){
console.log(selected,selectObj)
this.transactionForm.patchValue({recipient: selectObj.recipient, destination:
selectObj.destination, amount: selectObj.amount, reference: selectObj.reference})
}
关于javascript - 如何根据所选选项更新表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54133043/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!