Detailed explanation of the role of brackets in AngularJS

Detailed explanation of the role of brackets in AngularJS

1. The role of brackets

1.1 Square brackets [ ]

When the attribute name is enclosed in square brackets, the right side is assigned the value of the expression <br /> If the attribute does not have square brackets, the right side is assigned a string

<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 right side of the square brackets is an expression //In the component red: string = "blue";

1.2 Parentheses ( )

Parentheses are used for event binding, which triggers an event on an element and the bound method responds, such as

<div (click)="go()">gogo</div> //Put the event in the parentheses //Component class go() {
 //expression...
}

1.3 Curly Braces { { }}

Use curly braces { {expression}} This method is called interpolation and can be placed in the template

<div>{{good}}</div> //<div>Hello</div> 
 
//Component class good: string = "Hello";

1.4 String variables ${ }

Example

tes: string = "World";
test: string = `Hello ${goo}`; //test: string = "Hello World";

1.5 [()]

Commonly used for two-way binding operations

<input [(ngModel)]='test_input' /> // value= 'testNgClick'
 
//In the component test_input: any = 'testNgClick';

This is the end of this article about the role of brackets in AngularJS. For more information about the role of brackets in AngularJS, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Angular performance optimization: third-party components and lazy loading technology
  • Angular framework detailed explanation of view abstract definition
  • Angular SMS template verification code
  • A brief analysis on the problem of introducing ng-zorro into angular
  • Angular+Ionic uses queryParams to implement page jump value transfer
  • Example of implementing simple unit testing in Angular
  • AngularJs's $http sends a POST request, and PHP cannot receive Post data. Problems and solutions
  • Sample code for Angular+ionic to achieve folding and expanding effects
  • A brief discussion of 12 classic problems in Angular

<<:  Briefly describe the difference between MySQL and Oracle

>>:  How to modify the location of data files in CentOS6.7 mysql5.6.33

Recommend

Detailed explanation of React event binding

1. What is In react applications, event names are...

Detailed explanation of Vue's sync modifier

Table of contents 1. Instructions 2. Modifiers 3....

Best Practices for MySQL Upgrades

MySQL 5.7 adds many new features, such as: Online...

Vue achieves seamless carousel effect (marquee)

This article example shares the specific code of ...

MySQL group query optimization method

MySQL handles GROUP BY and DISTINCT queries simil...

Detailed explanation of Vue's custom event content distribution

1. This is a bit complicated to understand, I hop...

Basic usage of find_in_set function in mysql

Preface This is a new function I came across rece...

Input file custom button beautification (demo)

I have written such an article before, but I used...

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version: Method 1: Use the SET PASSWORD...

Native JS to achieve sliding button effect

The specific code of the sliding button made with...

How to view and terminate running background programs in Linux

Linux task management - background running and te...