Home  >  Article  >  Web Front-end  >  What are the uses of "?" and "!" in Angular?

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

青灯夜游
青灯夜游forward
2020-09-10 10:11:1212889browse

What are the uses of

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

! 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

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete