Angular 2 - Rohrwiederverwendung in mehreren Modulen - Fehler nicht gefunden oder doppelte Definition
Im arbeiten an Winkel 2 endgültige Veröffentlichung.
Ich habe @ deklariezwei Module: main app und eins für dasEinstellungsseite.
Dasas Modul @main deklariert global Pipes. Dieses Modul enthält auch das Einstellungsmodul.
app.module.ts
@NgModule({
imports: [BrowserModule, HttpModule, routing, FormsModule, SettingsModule],
declarations: [AppComponent, JsonStringifyPipe],
bootstrap: [AppComponent]
})
export class AppModule { }
settings.module.ts
@NgModule({
imports: [CommonModule, HttpModule, FormsModule, routing],
declarations: [SettingsComponent],
exports: [SettingsComponent],
providers: []
})
export class SettingsModule { }
Wenn Sie versuchen,Verwenden Sie die Pipe im Einstellungsmodul Ich bin Es wurde ein Fehler gemeldet, dass die Pipe nicht gefunden wurde.
zone.min.js?cb=bdf3d3f:1 Unhandled Promise rejection: Template parse errors:
The pipe 'jsonStringify' could not be found (" <td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>[ERROR ->]{{user | jsonStringify}}</td>
<td>{{ user.registered }}</td>
</tr"): ManageSettingsComponent@44:24 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse
Wenn ich die Pipe in das Einstellungsmodul einbinde, wird beanstandet, dass die beiden Module dieselbe Pipe haben.
zone.min.js?cb=bdf3d3f:1 Error: Error: Type JsonStringifyPipe is part of the declarations of 2 modules: SettingsModule and AppModule! Please consider moving JsonStringifyPipe to a higher module that imports SettingsModule and AppModule. You can also create a new NgModule that exports and includes JsonStringifyPipe then import that NgModule in SettingsModule and AppModule.
json-stringify.pipe.ts
@Pipe({name: 'jsonStringify'})
export class JsonStringifyPipe implements PipeTransform {
transform(object) {
// Return object as a string
return JSON.stringify(object);
}
}
Eine Idee dazu?