angular-template-form

Initializing Template Driven Form in Angular 7

柔情痞子 提交于 2021-02-11 06:59:42
问题 I'm looking to initialize certain form fields on a form and then call a function that has a if(this.form.valid) condition on it. on the ngOnInit function I have an API call that gets some basic info and fills it on the form: ngOnInit(){ this.apiService.getInfo(this.user.id).subscribe( userInfo => { this.formModel.fieldA = userInfo.A; this.formModel.fieldB = userInfo.B; this.formModel.fieldC = userInfo.C; this.doStuff(); } ); } However when calling this.doStuff() the form is invalid, even

Form with Custom Component does not recognize control

隐身守侯 提交于 2020-07-30 04:06:28
问题 I am using a custom component (custom-text) which has the below code @Component({ selector: 'custom-text, [custom-text]', templateUrl: './custom-text.template.html', styleUrls: ['./custom-text.component.scss'] }) export class CustomTextComponent implements OnInit { constructor() { } ngOnInit() { } } Inside the custom-text.template.html <mat-form-field> <input matInput id="controlid" name="controlname" maxlength="8" [(ngModel)]="value"> </mat-form-field> When I include this control inside a

Form with Custom Component does not recognize control

让人想犯罪 __ 提交于 2020-07-30 04:06:22
问题 I am using a custom component (custom-text) which has the below code @Component({ selector: 'custom-text, [custom-text]', templateUrl: './custom-text.template.html', styleUrls: ['./custom-text.component.scss'] }) export class CustomTextComponent implements OnInit { constructor() { } ngOnInit() { } } Inside the custom-text.template.html <mat-form-field> <input matInput id="controlid" name="controlname" maxlength="8" [(ngModel)]="value"> </mat-form-field> When I include this control inside a

Mixing Reactive Form with Template Form

帅比萌擦擦* 提交于 2020-01-30 12:57:25
问题 I have built a big form with lots of input using Template Form. Now I have got a requirement to add a part of input dynamically. Since adding inputs dynamically seems easier with Reactive Form, I would like to change that specific part of inputs to Reactive Form. So is it possible to mix reactive forms and template forms in a same form tag? 回答1: You can mix both reactive forms and template driven forms, but it is highly not recommended. This is because using ngModel on reactive forms goes

Multi-layer form using Reactive forms in Angular 6

人走茶凉 提交于 2019-12-25 01:45:29
问题 I am trying to develop a web application, which displays a set of questions to the user. Questions are segregated based on Categories . The application is developed using Angular6. Questions are fetched using the backend REST service. An interface is created on the client side which mocks the REST response structure, which has several subinterfaces to back the complex internal structure. The response will be mapped as a List of this interface. Following is the structure of the interface. My