Bidirectional binding principle Two-way binding combines property binding with event binding. Angular's two-way binding syntax is a combination of square brackets and parentheses [()]. [] is used for property binding, and () is used for event binding. The naming rule is [input name] + Change.
Therefore, there are ngModel and ngModelChange in the form two-way binding, and you can also customize the two-way binding properties. ngModelTwo-way binding to form elements import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-bind', template: ` <div> <div>Name: {{ name }}</div> <input type="text" style="width: 300px;" nz-input name="name" [(ngModel)]="name" autocomplete="off"> </div> ` }) export class BindComponent implements OnInit { name = ''; constructor() { } ngOnInit(): void { } } RenderingCustom two-way binding propertiesComponent-html<div> <div>inner: {{ value }}</div> <input style="width: 300px;" nz-input (input)="onInput(input.value)" #input autocomplete="off"> </div> Component-tsimport { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; @Component({ selector: 'app-inner', templateUrl: './inner.component.html', styleUrls: ['./inner.component.scss'] }) export class InnerComponent implements OnInit { // Set input properties @Input() value!: string; // Set output event @Output() valueChange: EventEmitter<string> = new EventEmitter(); constructor() { } ngOnInit(): void { } onInput(value: string){ // Trigger output event - output data this.valueChange.emit(value); } } External useimport { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-outer', template: ` <div> <div>Name: {{ name }}</div> <app-inner [(value)]="name"></app-inner> </div> ` }) export class OuterComponent implements OnInit { name = ''; constructor() { } ngOnInit(): void { } } Rendering SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: CSS3 filter (filter) to achieve the sample code of gray or black mode of web page
>>: Linux system calls for operating files
No more nonsense, post code HTML part <div cla...
This article example shares the specific code of ...
When deploying uwsgi+nginx proxy Django, access u...
In actual work, JavaScript regular expressions ar...
Mysql8.0.12 decompression version installation me...
Use the find command to find files larger than a ...
Kernel: [root@opop ~]# cat /etc/centos-release Ce...
Nowadays, whether you are working on software or w...
1. What is Docker? Everyone knows about virtual m...
TABLE> <TR> <TD> <TH> <CA...
Assume there are two Linux servers A and B, and w...
1. First register your own dockerhub account, reg...
introduce In a distributed system, distributed lo...
01. VMware Workstation Pro 15 Download Download: ...
As we all know, there are two types of images in c...