私は次のようなクラスファイルを持っています。角度の反応形式を使用してtypescriptクラスとオブジェクトを使用してフォーム要素を生成する方法
export class ClassA {
description: string;
type: string;
order: number;
constructor(descrption: string, type: string, order: number) {
this.description = descrption;
this.type = type;
this.order = order;
}
}
ここで、このクラスをタイプスクリプトで使用してフォーム要素(テキストボックス)を作成します。私のhtmlページで コードすなわち(.TS)私のtypescriptファイルで
<form [formGroup]="myForm">
</form>
を次のようなコードをファイルは次のようです。
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
arr = Array<ClassA>();
r1: ClassA;
r2: ClassA;
myForm:FormGroup;
constructor() {
this.r1 = new ClassA('description1', 'text', 1);
this.arr.push(this.r1);
this.r2 = new ClassA('description2', 'text', 2);
this.arr.push(this.r2);
}
ngOnInit() {
console.log(this.arr);
}
}
このformGroupを使用すると、これらのクラスフィールドをフォームの入力要素として動的に作成する方法はありますか?
あなたのタイトルは、あなたの質問に矛盾します。反応型のアプローチが必要な場合は、テンプレート駆動型のアプローチを求めないでください。 –
ありがとうございます。私は質問を変更しました。あなたはそれを調べて助けてください。\ – roopteja