首页 > 解决方案 > AngularDart:在使用 *ngIf 时,任何指令都没有使用嵌入模板错误的属性绑定 ngIf

问题描述

我正在使用 AngularDart,我需要根据布尔值registerDisplay显示和隐藏组件。尝试使用*ngIf,但抛出错误。下面是html。

app_component.html:

<div *ngIf="!registerDisplay">
    <register-component></register-component>
</div>

在此处输入图像描述

可能是什么原因。我遇到了 Angular typescript 中错误的解决方案。但这不适用于飞镖。请建议。

标签: dartangular-dartdart-htmlangular-ng-if

解决方案


您需要注册要在模板中使用的指令

@Component(
  selector: 'my-component',
  directives: const [
    MaterialButtonComponent,
    MaterialIconComponent,
    MaterialTooltipDirective,
    ...
    NgIf,
    ...
  ],

您可以通过添加来注册 Angular 本身提供的公共集,而不是单独注册每个指令

coreDirectives,

directives列表中。

另请参阅https://github.com/dart-lang/angular/blob/master/angular/lib/src/common/common_directives.dart


推荐阅读