? 用来检查 问号前面的变量为 null 或 undefined 时,程序不会出错。

  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
! 用来检查 感叹号后面的变量为 null 或 undefined 时, 程序不会出错。
stu3: Student;

<h1>stu3 id{{stu3?.id}}</h1>                // stu3 id
<h1>stu3 name{{stu3?.name}}</h1>      // stu3 name

相关文章:

  • 2021-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-01-14
  • 2021-09-12
  • 2022-01-31
猜你喜欢
  • 2022-02-16
  • 2021-11-12
  • 2021-10-26
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案