NullInjectorError:没有NgZone的提供者

时间:2018-01-15 00:14:38

标签: angular angular-material2 angular5 ngzone

我创建了带有材质设计的角度库(package.json如下)

{
  "name": "angular-lib",
  "version": "0.0.0",
  "license": "UNLICENSED",
  "dependencies": {
    "@angular/core": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/material": "^5.0.4",
    "@angular/forms": "^5.2.0",
    "@angular/animations": "^5.2.0",
    "@angular/cdk": "^5.0.4",
    "@angular/platform-browser": "^5.2.0",
    "zone.js": "^0.8.20"
  }
}

当我在此库中包含时:

import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatCardModule, MatCommonModule } from '@angular/material';

当在这个库中时,所有内容都被导入

@NgModule({
  imports: [
    CommonModule,
    NoopAnimationsModule,
    MatCardModule
  ],
...

我收到错误:

Error: StaticInjectorError(AppModule)[ApplicationRef -> NgZone]: 
  StaticInjectorError(Platform: core)[ApplicationRef -> NgZone]: 
    NullInjectorError: No provider for NgZone!
    at _NullInjector.webpackJsonp../node_modules/@angular/core/esm5/core.js._NullInjector.get (core.js:994)
    at resolveToken (core.js:1292)
    at tryResolveToken (core.js:1234)
    at StaticInjector.webpackJsonp../node_modules/@angular/core/esm5/core.js.StaticInjector.get (core.js:1102)
    at resolveToken (core.js:1292)
    at tryResolveToken (core.js:1234)
    at StaticInjector.webpackJsonp../node_modules/@angular/core/esm5/core.js.StaticInjector.get (core.js:1102)
    at resolveNgModuleDep (core.js:10836)
    at _createClass (core.js:10881)
    at _createProviderInstance$1 (core.js:10847)

1 个答案:

答案 0 :(得分:0)

我找到了临时解决方案...... 我的角度库 node_modules 来自 angular-cli预览应用的符号链接工作正常。

ln -s <angular-cli-preview-app>/node_modules <my-angular-library>/node_modules