相关疑难解决方法(0)

Angular - ng-template,其中ngIf内的参数位于ngFor内

我正在尝试构建此模板:

<ul>
    <li *ngFor='let link of links'>
        <ng-container *ngIf="link.type == 'complex'; then complexLink else simpleLink"></ng-container>
    </li>
</ul>

<ng-template #simpleLink>
    ...
    {{ link.some_property }}
</ng-template>

<ng-template #complexLink>
    ...
    {{ link.some_property }}
</ng-template>
Run Code Online (Sandbox Code Playgroud)

问题是在ng-template中未定义链接变量,因此我得到访问未定义的'some_property'的错误.

我很想知道如何将链接变量从ngFor传递到ng-template

很高兴知道这个问题是否有多种解决方案.

angular-template ng-template angular

31
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

angular-template ×1

ng-template ×1