use*_*236 65 null-coalescing-operator typescript angular
在角度2中等效的空合并运算符(??)是什么.
在C#中我们可以执行一个操作:
string str = name ?? FirstName ?? "First Name is null";
Run Code Online (Sandbox Code Playgroud)
Rom*_*n C 107
通过||操作员执行合并,即
let str:string = name || FirstName || "name is null and FirstName is null";
Run Code Online (Sandbox Code Playgroud)
您还可以阅读此问题以获取更多详细信息和说明.
Typescript 引入了与 version 的 null 合并3.7,因此如果您在运行3.7或更高版本,您可以简单地编写:
const str = name ?? firstName ?? "Name and First Name are both null";
const x = foo?.bar.baz() ?? bizz();
Run Code Online (Sandbox Code Playgroud)
请参阅https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing。
从 Angular 12 开始,您也可以??在模板中使用。
| 归档时间: |
|
| 查看次数: |
26898 次 |
| 最近记录: |