我想要做的是使用Firebase身份驗證爲Angular2項目創建登錄。當我嘗試這樣做,我得到這個錯誤:Angular2:未處理的Promise拒絕:模板解析錯誤:'login'不是已知的元素
Unhandled Promise rejection:
Template parse errors: 'login' is not a known element:
1. If 'login' is an Angular component, then verify that it is part of this module.
2. If 'login' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
which comes from a direct reference to the DB child
<em>static</em></strong>: {{direct}} <hr/> [ERROR ->]<login
*ngIf='!isAuth'></login> <div *ngIf='isAuth'>
<h3>Nicely done!</h3> "): [email protected]:2 'logout' is not a known element:
1. If 'logout' is an Angular component, then verify that it is part of this module.
2. If 'logout' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
<p><strong>Your private message:</strong> {{private}}</p>
<hr/>
[ERROR ->]<logout></logout> </div>"): [email protected]:4
; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse
errors: 'login' is not a known element: 1. If 'login' is an Angular
component, then verify that it is part of this module. 2. If 'login'
is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the
'@NgModule.schema' of this component to suppress this message. ("
which comes from a direct reference to the DB child
<em>static</em></strong>: {{direct}} <hr/> [ERROR ->]<login
*ngIf='!isAuth'></login> <div *ngIf='isAuth'> <h3>Nicely done!</h3> "): [email protected]:2 'logout' is not a known element: 1. If 'logout'
is an Angular component, then verify that it is part of this module.
2. If 'logout' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
<p><strong>Your private message:</strong> {{private}}</p> <hr/> [ERROR
->]<logout></logout> </div>"): [email protected]:4
TemplateParser</[email protected]://localhost:4200/main.bundle.js:15261:19
RuntimeCompiler</[email protected]://localhost:4200/main.bundle.js:33617:30
RuntimeCompiler</RuntimeCompiler.prototype._compileComponents/compile/<@http://localhost:4200/main.bundle.js:33540:77
RuntimeCompiler</RuntimeCompiler.prototype._compileComponents/[email protected]://localhost:4200/main.bundle.js:33540:37
Zone$1</ZoneDelegate</[email protected]://localhost:4200/main.bundle.js:64951:19
Zone$1</Zone</[email protected]://localhost:4200/main.bundle.js:64844:24
scheduleResolveOrReject/<@http://localhost:4200/main.bundle.js:65210:52
Zone$1</ZoneDelegate</[email protected]://localhost:4200/main.bundle.js:64984:23
Zone$1</Zone</[email protected]://localhost:4200/main.bundle.js:64884:28
[email protected]://localhost:4200/main.bundle.js:65116:25
這裏是我的項目結構:
這裏是我的app.component.ts
:
import { Component } from '@angular/core';
import { DataService } from './data.service';
import { UserService } from './user.service';
import { LoginComponent } from '../app/login/login.component';
import { LogoutComponent } from '../app/logout/logout.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [DataService, UserService]
})
export class AppComponent {
title = 'app works!';
public message: string;
public direct: string;
public private: string;
public isAuth: boolean;
constructor (private _data: DataService, private _user: UserService) {}
ngOnInit() {
this._user.auth.onAuthStateChanged(user => this.isAuth = !!user);
// this method...
this._data.db.child('static').on('value', data => {
this.message = data.val();
});
// ...fetches the same data as this method
this._data.staticData.on('value', data => {
this.direct = data.val();
});
this._data.db.child('private').on('value', data => {
this.private = data.val();
});
}
}
這裏是我的登陸模塊data.service.ts
:
import { Injectable } from '@angular/core';
@Injectable()
export class DataService {
public db: any;
public staticData: any;
constructor() {
this.db = firebase.database().ref('/');
this.staticData = firebase.database().ref('/static');
}
}
我在這裏錯過了什麼?如何解決錯誤?
它是由我使用「ng生成組件登錄」和「ng生成組件註銷」 –
在哪裏進行模塊? –
你的意思是在app.module.ts? –