我知道还有其他一些类似于我的问题,但是我无法找到符合我情况的任何问题。我有一个适用于多个应用程序的包。在这个包中有一个名为AppReadyEvent的注射剂,它基于这篇文章:
我创建了原始包装的简化版本,而简化版本只是这样:
appreadyservice.ts
import { Injectable, Inject } from '@angular/core';
import { DOCUMENT } from "@angular/common"; // EDIT - was: @angular/platform-browser
@Injectable()
export class AppReadyEvent {
private doc: Document;
private isAppReady: boolean;
constructor(@Inject(DOCUMENT) doc: any ) {
this.doc = doc;
this.isAppReady = false;
}
public trigger(): void {
if ( this.isAppReady ) {
return;
}
let bubbles = true;
let bubbles2 = true;
let cancelable = false;
this.doc.dispatchEvent( this.createEvent('appready', bubbles, cancelable, bubbles2) );
this.isAppReady = true;
}
private createEvent(eventType: string, bubbles: boolean, cancelable: boolean, bubbles2: boolean): Event {
try {
var customEvent: any = new CustomEvent(
eventType,
{ bubbles: bubbles,
cancelable: cancelable }
);
} catch ( error ) {
var customEvent: any = this.doc.createEvent( 'CustomEvent' );
customEvent.initCustomEvent( eventType, bubbles, cancelable, bubbles2);
}
return( customEvent );
}
}
index.ts:
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AppReadyEvent } from './src/appreadyservice';
export * from './src/appreadyservice';
@NgModule({
declarations: [
],
imports: [
CommonModule
],
exports: [
]
})
export class TestModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: TestModule,
providers: [AppReadyEvent]
};
}
}
的package.json:
{
"name": "test-package-a6",
"version": "1.0.0",
"description": "Testing Packages with Angular 6",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {},
"author": "Dave Nottage",
"license": "MIT",
"dependencies": {
"@angular/cli": "^6.0.8",
"@angular/common": "^6.0.5",
"@angular/core": "^6.0.5",
"@angular/platform-browser": "^6.0.5"
}
}
tsconfig.json:
{
"compilerOptions": {
"skipLibCheck": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "ES5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"dist",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"genDir": "compiled"
}
}
在测试项目中:
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts:
import { Component } from '@angular/core';
import { AppReadyEvent } from 'test-package-a6';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [AppReadyEvent]
})
export class AppComponent {
title = 'app';
}
一旦我和他们在一起,我就会使用:
ng build --prod
并收到可怕的:
ERROR in : Can't resolve all parameters for AppReadyEvent in D:/DEVELOP/test_a6/node_modules/test-package-a6/dist/src/appreadyservice.d.ts: (?).
任何线索?