'flash-messages' не является известным элементом angular 6 - PullRequest
0 голосов
/ 13 октября 2018

У меня странная проблема, я использую angular2-flash-сообщения в своем проекте Angular 6.Я уже установил его через npm, добавил его в app.module.ts как модуль

import { FlashMessagesModule } from 'angular2-flash-messages';

, добавил его в раздел модулей

imports: [
BrowserModule,
BrowserAnimationsModule,
DemoMaterialModule,
FormsModule,
FlexLayoutModule,
HttpClientModule,
PerfectScrollbarModule,
SharedModule,
AngularFireModule.initializeApp(environment.firebase, 'angular-auth-firebase'),
AngularFireDatabaseModule,
AngularFireAuthModule,
RouterModule.forRoot(AppRoutes),
FlashMessagesModule.forRoot()

и добавил сервис в свойlogin.component.ts

import { FlashMessagesService } from 'angular2-flash-messages';

, но когда я добавляю

<flash-messages></flash-messages>

в login.component.html, в консоли ошибок выдается ошибка

ERROR Error: Uncaught (in promise): Error: Template parse errors:
'flash-messages' is not a known element:
1. If 'flash-messages' is an Angular component, then verify that it is part of this module.
2. If 'flash-messages' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<flash-messages></flash-messages>
<div class="login-register"  style="background-image:url(assets/ima"): ng:///AuthenticationModule/LoginComponent.html@0:0
Error: Template parse errors:
'flash-messages' is not a known element:
1. If 'flash-messages' is an Angular component, then verify that it is part of this module.
2. If 'flash-messages' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<flash-messages></flash-messages>
<div class="login-register"  style="background-image:url(assets/ima"): ng:///AuthenticationModule/LoginComponent.html@0:0
    at syntaxError (compiler.js:215)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22696)
    at compiler.js:22639
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639)
    at compiler.js:22549
    at Object.then (compiler.js:206)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
    at syntaxError (compiler.js:215)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22696)
    at compiler.js:22639
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639)
    at compiler.js:22549
    at Object.then (compiler.js:206)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4053)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)

но если я добавлю

<flash-messages></flash-messages>

к основному компоненту приложения (app.component.html), как это

<router-outlet>
  <flash-messages></flash-messages>
</router-outlet>

Все работает нормально.

Как я могурешить это?

1 Ответ

0 голосов
/ 13 октября 2018

Вы должны импортировать FlashMessagesModule для каждого модуля, в котором вы хотите его использовать.В некоторых случаях вам нужно импортировать .forChild(), когда вы уже импортировали его, например, RouterModule.forChild(routes), но не для FlashMessagesModule.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...