I am a little bit confused, for some tutorial use # to get the input, while some use the [(ngModel)]
相关问题
- Angular RxJS mergeMap types
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- How to update placeholder text in ng2-smart-table?
- How to instantiate Http service in main.ts manuall
- Angular: ngc or tsc?
相关文章
- angular脚手架在ie9+下兼容问题
- angular 前端项目 build 报错 "Cannot find module 'le
- Angular Material Stepper causes mat-formfield to v
- After upgrade to Angular 9 cannot find variable in
- is there any difference between import { Observabl
- Suppress “Circular dependency detected” suppress w
- How can you get current positional information abo
- Angular material table not showing data
#xxx
#xxx
allows you to get an element reference.listenes to the change event and calls
onChange()
and passes the inputsvalue
propertyFor two-way binding you also need
NgModel
uses the
NgModel
directive that allows to integrate DOM input elements and custom components into Angular form functionality. It can also be used without a form.NgModel
is an abstraction over all kinds of elements and components, while above (#inp
) example only works for input elements that have avalue
property and emit achange
event.is the short form of
which shows it is for two-way binding.
hint
#xxx
returns a component or directive instance, if the element is not a plain DOM element but an Angular component or has an Angular directive applied.The #name syntax is a template reference which refers to the html object, more information can be found on in the Angular docs: Angular template guide
The [(ngModel)] is setting two way binding on the elements value and assigning that to a variable.