Hellom's Studio.

关于 ionic4 中 *ngif 在 自定义组件 里面报错的问题

字数统计: 112阅读时长: 1 min
2019/07/12 Share

具体报错内容:

Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".

解决办法:

  • 导入 import { CommonModule } from '@angular/common';

  • imports 中引入 CommonModule 模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//components.module.ts

import { NgModule } from '@angular/core';
import { BlackListComponent } from '../components/black-list/black-list.component';
import { CommonModule } from '@angular/common'; // <== 添加CommonModule


@NgModule({
declarations: [
BlackListComponent
],
imports: [
CommonModule,// <== 引入 CommonModule组件
],
exports: [
BlackListComponent
],
entryComponents: [
BlackListComponent
],
})
export class ComponentsModule { }
CATALOG
  1. 1. 具体报错内容:
  2. 2. 解决办法: