Angular ng-template 用作语法

标签 angular

当使用带星号的 ngIf 时,我们可以执行以下操作:

<ng-container *ngIf="obj | async as result">{{result}}</ng-container>

我们如何使用 ng-template 做同样的事情?

<ng-template [ngIf]="(obs | async) as result">
    {{result}}
</ng-template>

上面的代码抛出错误。

最佳答案

是的,您也可以在 ng-template 中使用这种语法,如下所示:

<ng-template [ngIf]="obs | async" let-result="ngIf">
   {{result}}
</ng-template>

<ng-template [ngIf]="obs | async" let-result>
   {{result}}
</ng-template>

更多细节见:

关于Angular ng-template 用作语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55299950/

相关文章:

javascript - 使用 Lodash 对 Javascript 数组进行分组

Angular 5 Service worker 不工作/不缓存背景图像

angular - 如何更改使用 Angular Material 选项卡的组件的单元测试中的选项卡

angular - 找不到模块@angular/compiler-cli/src/tooling

angular - dart angular2 - 在模板中渲染对象时出现空错误

javascript - Angular 4 jquery 不起作用

angular - angular http请求同时发送两次

angular - 函数声明错误 - 意外的标记。需要构造函数、方法、访问器或属性

angular - 单击按钮时, Angular 4 中的 react 形式提交复选框值数组

angular - 如何使用类构造函数为类实例定义接口(interface)