0
我正在用angular-cli 1.2.6构建一个小型的Angular 4应用程序。在开发过程中一切正常,并且它使用ng build --dist
成功构建。但在运行时,第三方供应商之一toastr
我用作服务没有找到 - 当注入时它是undefined
。这是我如何包含到项目:Angular 4 with angular-cli - 找不到AOT的第三方提供商
.angular-cli.json
...
"scripts": [
...
"../node_modules/toastr/build/toastr.min.js"
],
...
我已经在一个单独的文件中创建一个注射令牌:
import {InjectionToken} from '@angular/core';
import {IToastr} from './toastr.model';
export let TOASTR_TOKEN = new InjectionToken<IToastr>('toastr');
然后app.module.ts
我包括它作为提供者:
import {TOASTR_TOKEN} from './common/tokens';
let toastr = window['toastr'];
...
providers: [
...
{provide: TOASTR_TOKEN, useValue: toastr}
],
...
:/ /rahulrsingh09.github.io/AngularConcepts/faq)关于如何在Angular中包含第三方库 –