Template parse errors: Can't bind to 'ngStyle' since it isn't a known property of 'div'. ("

  • 1、背景

开发个公共组件,在组件中使用指令一直报错。

template: `
    
{{item.title}}
{{item.value}}
{{title}}
{{this.util.toThousands(value, null)}}
`,
  • 2、问题原因

angular的指令模块BrowserModule CommonModule 未导入。

  • 3、解决办法

在app.module.ts中导入BrowserModule 

import {BrowserModule} from '@angular/platform-browser';
@NgModule({
    declarations: [
        
    ],
    imports: [
        BrowserModule,
        
    ],
    providers: [
        
    ],
    bootstrap: [AppComponent]
})

在你需要使用的模块中导入CommonModule

import { NgModule } from '@angular/core';
import { D3WidgetComponent } from './d3.widget';
import { SamllCardComponent } from './small.card';
import { CommonModule } from '@angular/common';
export const SCHEMA_THIRDS_COMPONENTS = [
  D3WidgetComponent,
  SamllCardComponent,
];

@NgModule({
  declarations: SCHEMA_THIRDS_COMPONENTS,
  entryComponents: SCHEMA_THIRDS_COMPONENTS,
  imports: [CommonModule],
  exports: [...SCHEMA_THIRDS_COMPONENTS],
})
export class JsonSchemaModule {}

你可能感兴趣的:(angular,ng-alain)