Home > Web Front-end > JS Tutorial > What are the uses of '?' and '!' in Angular?

What are the uses of '?' and '!' in Angular?

青灯夜游
Release: 2021-02-01 11:48:07
forward
12961 people have browsed it

What are the uses of '?' and '!' in Angular?

Related tutorial recommendations: "angularjs tutorial"

? Used When checking whether the variable before the question mark is null or undefined, the program will not make an error.

  stu2: Student = {
    id: 1,
    name: undefined,
    age: 3
  };
  
<h1>stu2 name {{stu2!.name}}</h1>  // stu2 name 
<h1>stu2 id {{stu2!.id}}</h1>            // stu2 id 1
Copy after login

! Used to check that the program will not make an error when the variable after the exclamation mark is null or undefined.

stu3: Student;
 
<h1>stu3 id{{stu3?.id}}</h1>                // stu3 id
<h1>stu3 name{{stu3?.name}}</h1>      // stu3 name
Copy after login

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of What are the uses of '?' and '!' in Angular?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template