Angular - NgIf 不在组件上工作:"NG0303: Can't bind to 'ngIf' since it isn't a known property of 'p'."

Angular - NgIf not working on component: "NG0303: Can't bind to 'ngIf' since it isn't a known property of 'p'."

我正在尝试在组件上使用 ngif 指令,但控制台上不断出现以下错误:“NG0303:无法绑定到 'ngIf',因为它不是已知的 属性 of 'p'.",元素就没有出现。此外,我正在为某些元素使用 po-ui 框架。

组件的 ts 和 html 代码如下:

cadastro-usuario.component.ts:

import { Component, OnInit } from '@angular/core';
import { PoButtonGroupModule } from '@po-ui/ng-components';
import { PoButtonGroupItem } from '@po-ui/ng-components';

@Component({
  selector: 'app-cadastro-usuario',
  templateUrl: './cadastro-usuario.component.html',
  styleUrls: ['./cadastro-usuario.component.css']
})
export class CadastroUsuarioComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
  
  buttons: Array<PoButtonGroupItem> = [
    { label: 'Vínculo', action: this.vinculo.bind(this) },
    { label: 'Endereço', action: this.endereco.bind(this) },
    { label: 'Contatos', action: this.contatos.bind(this) },
  ];

  vinculo() {
  alert("vinculo");
  }
  
  endereco() {
  alert("endereco");
  }
  
  contatos() {
  alert("contatos");
  }
}

cadastro-usuario.component.html:

<p style="display:inline-block; margin-left:80px; margin-top:20px; width: 600px;">
    <po-button-group class="po-md-12" [p-buttons]="buttons"> </po-button-group>
</p>

<br>

<p *ngIf="true" style="display:inline-block; margin-left:80px; margin-top:20px; width: 300px;">
    <po-input name="vinculo" p-label="Vínculo"> </po-input>
</p>

我想这可能是重复的,但你应该导入

CommonModule and BrowserModule

在您的组件模块下,如果您不确定,只需将它添加到 app.module.ts 文件中,如下所示:

1 进口:

import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';

2 在 NgModule 下:

@NgModule({
  imports: [
    CommonModule,
    BrowserModule
...