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 custom swiper component in JavaScript

Table of contents Effect display Component Settin...

WeChat applet custom scroll-view example code

Mini Program Custom Scroll-View Scroll Bar Withou...

Implementation of React page turner (including front and back ends)

Table of contents front end According to the abov...

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

A complete guide on how to query and delete duplicate records in MySQL

Preface This article mainly introduces the method...

Vue implements the function of calling the mobile phone camera and album

This article shares the specific code of Vue to a...

Use of MySQL official export tool mysqlpump

Table of contents Introduction Instructions Actua...

How to use regular expression query in MySql

Regular expressions are often used to search and ...

Detailed explanation of how to exit Docker container without closing it

After entering the Docker container, if you exit ...

SMS verification code login function based on antd pro (process analysis)

Table of contents summary Overall process front e...

SQL Server database error 5123 solution

Because I have a database tutorial based on SQL S...

Html tips to make your code semantic

Html semantics seems to be a commonplace issue. G...

MySQL table auto-increment id overflow fault review solution

Problem: The overflow of the auto-increment ID in...

Detailed explanation of Vue's calculated properties

1. What is a calculated attribute? In plain words...