angular-reactive-forms

How can I bind a form to a model in Angular 6 using reactive forms?

点点圈 提交于 2020-12-01 09:02:17
问题 Prior to angular 6, I was using [(ngModel)] to directly bind my form field to the model. This is now deprecated (can't use with reactive forms) and I am not sure how to update my model with the form values. I could use form.getRawValue() but this would require me to replace my current model with the new rawValue - this is not favourable since my main model is larger and has more fields than the local form model. Any ideas? 回答1: Don't use [(ngModel)] ! Reactive forms are much nicer. They make

ANGULAR 6: error TS2315: Type 'ModuleWithProviders' is not generic

徘徊边缘 提交于 2020-11-29 04:37:44
问题 Hello I am experience a issue that I cannot relate to anything. I show some of my code hoping it can be of any use. Consider that the issue appeared once I started on creating a Reactive Form. First of all, here it is my package.json: { "name": "name", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^6.0.3", "@angular/common": "^6.0.3", "

Way to inject angular FormBuilder service to dynamic component

别来无恙 提交于 2020-11-28 09:16:59
问题 I'm trying to inject the FormBuilder service to a dynamic component this way: Template: ... <div #vc></div> ... Component: @ViewChild('vc', { read: ViewContainerRef }) _container: ViewContainerRef; ... constructor(private fb: FormBuilder, private componentFactoryResolver: ComponentFactoryResolver, private _compiler: Compiler, private _injector: Injector, private _m: NgModuleRef<any>) { } ... ngAfterViewInit() { let allPms: any[] = null; let template = ''; // construct template on the fly