虽然我已将AuthComponent
添加到AuthModule
但是,我收到此错误:
Unhandled Promise rejection: Template parse errors:
'auth' is not a known element:
1. If 'auth' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("ystem.import('public/app/auth').catch(function (err) { console.error(err); });</script></head><body>[ERROR ->]<auth><div class="progress-container"><div class="progress"><div class="indeterminate"></div></div></"): ng:///success-snackBar.component@0:861 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:
我已经阅读了与此问题相关的大部分主题(未处理承诺拒绝:模板解析错误)但是,我无法解决我的问题。
这是我的组件:
import {Component, ViewContainerRef} from "@angular/core";
@Component({
selector: 'auth',
templateUrl: './auth.component.html'
})
export class AuthComponent {
}
登录表单:
<head>
<script src='systemjs.config.js'></script>
<script>
System.import('public/app/auth').catch(function (err) { console.error(err); })
</script>
</head>
<body>
<auth></auth> // the selector is used here and the error comes from here
</body>
AuthModule:
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {FormsModule} from "@angular/forms";
import {BrowserModule} from "@angular/platform-browser";
import {LoginModule} from "./login/login.module";
import {AuthService} from "./auth.service";
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {AuthComponent} from "./auth/auth.component";
import {HttpClientModule} from "@angular/common/http";
@NgModule({
imports: [
BrowserModule,
CommonModule,
BrowserAnimationsModule,
FormsModule,
LoginModule,
HttpClientModule
],
declarations: [
AuthComponent
],
providers: [
AuthService
],
exports: [
AuthComponent
],
bootstrap: [AuthComponent]
})
export class AuthModule {
}
更新
像这样引导AuthModule
:
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {AuthModule} from "./auth.module";
platformBrowserDynamic().bootstrapModule(AuthModule);
任何帮助都将不胜感激。