what is the difference between angular responsive forms and template-driven forms, and what are their applicable scenarios?
what is the difference between angular responsive forms and template-driven forms, and what are their applicable scenarios?
to put it simply, the template driver uses ngModel to bind controls to data, and Angular will listen for changes in values asynchronously. In our view, this is a black box operation that we can't control. The responsive form processes the value and state of the control in real time through FormControl and so on, and the controllability is greatly improved. Choose which one to see if you want the data to be controllable.
can be simply understood that responsive forms are dynamic and template-driven forms are static.
template-driven forms are suitable for fixed pages, such as login pages, and template-driven forms can be used.
responsive forms are suitable for dynamic pages, usually maintaining a formGroup
. Any component that you want to add for verification, just bind a formControl
, then add it to formGroup, and the next state can be obtained through formGroup.
for example, I click create user, then I need to open a dialog to specify the value of each field, and then validate it.
because the same dialog box will also be used to create tasks, create companies, etc., so this dialog box is dynamic, so you can't use templates to drive the form.
what should I do?
in the dialog component, I can create a formGroup formGroup: FormGroup = new FormGroup ()
and then use formGroup to add formControls for the field, in dialog
this.formGroup.addControl('name', new FormControl())
this.formGroup.addControl('age', new FormControl())
this.formGroup.addControl('hobby', new FormControl())
this.formGroup.addControl('gender', new FormControl())
Previous: Problems installing image-webpack-loader
Next: Vue mint ui real-time search for IOS compatibility issues
to use a rich text editor in the project, I found Quill I introduced into app after npm install ng2-quill-editor. import { QuillEditorModule } from ng2-quill-editor ; imports: [ QuillEditorModule, ], an error will be reported at thi...
mat-datepicker read the document through Google Translation and did not find out how to choose only the year and year. Does anyone know how to use it? if anyone does, by the way, tell me how to format MM YYYY into YYYY MM,. I reported all kinds of errors...
how to inject js module of remote umd specification into angular via system.js We want to implement a mechanism like wordpress that can load plug-ins (menus). ...
there are more than a dozen pages for inexplicable reasons, but there is only one page for uploading files. No matter whether it is route.navigate to any page or routerLink= written directly on the button, the entire page will be refreshed again after ju...
import { NgZorroAntdModule } from ng-zorro-antd ; mports: [ NgZorroAntdModule ], it s just configured according to the official website, but it s too big. Have you ever met a great god? ...