1. The role of brackets
1.1 Square Brackets [ ]
After the property name is added with square brackets, the value on the right isValue of expression
If the property does not have square brackets, the value on the right isString
<div class="red">red</div> //The class name here is red<div [class]="red">red</div> //The class name here is blue, which means that the expression is on the right side of the square brackets. //In the componentred: string = "blue";
1.2 Brackets ( )
Parentheses are used for event binding, which means triggering events on elements, and the binding method will respond, such as
<div (click)="go()">gogo</div> //Put events in parentheses //Component Classgo() { //expression...}
1.3 Curly Braces {{ }}
Use curly braces{{expression}}This method is called interpolation and can be placed in a template
<div>{{good}}</div> //<div>Hello</div> //Component Classgood: string = "Hello";
1.4 String variables${ }
Give an example
tes: string = "World"; test: string = `Hello ${goo}`; //test: string = "Hello World";
1.5 [()]
Commonly used to do two-way binding operations
<input [(ngModel)]='test_input' /> // value= 'testNgClick' //In the componenttest_input: any = 'testNgClick';
This is the end of this article about the role of AngularJS brackets. For more information about the role of AngularJS brackets, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!