2016-10-12 14 views
1

私はソーシャルネットワーク経由でログインするサービスを作成しました。 私の問題は使用中にエラーが発生しています。 は私の主なコンポーネントは次のとおりです。サービスを利用できません

import {Component, ViewEncapsulation} from '@angular/core'; 
import {UserData} from '../../theme/services/userData'; 
@Component({ 
    selector: 'login', 
    encapsulation: ViewEncapsulation.None, 
    styles: [require('./login.scss')], 
    template: require('./login.html'), 
}) 
export class Login { 
    constructor(public _userData: UserData) { 

    } 

    login(form: string) { 
    this._userData.login(form); 

    } 

サービス:

import {Injectable} from '@angular/core'; 
import {AngularFire, AuthProviders} from 'angularfire2'; 
@Injectable() 
export class UserData { 
    user = {}; 
    isAuth = false; 

    constructor(public af: AngularFire) { 
    debugger; 
    this.af.auth.subscribe(user => this._changeState(user)); 
    } 

エラーは以下のとおりです。

error_handler.js:46 EXCEPTION: Uncaught (in promise): Error: Error in ./Login class Login_Host - inline template:0:0 caused by: No provider for UserData!ErrorHandler.handleError @ error_handler.js:46next @ application_ref.js:291schedulerFn @ async.js:89SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:81onError @ ng_zone.js:123onHandleError @ ng_zone_impl.js:65ZoneDelegate.handleError @ zone.js:207Zone.runGuarded @ zone.js:113_loop_1 @ zone.js:379drainMicroTaskQueue @ zone.js:386 error_handler.js:51 ORIGINAL STACKTRACE:ErrorHandler.handleError @ error_handler.js:51next @ application_ref.js:291schedulerFn @ async.js:89SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:81onError @ ng_zone.js:123onHandleError @ ng_zone_impl.js:65ZoneDelegate.handleError @ zone.js:207Zone.runGuarded @ zone.js:113_loop_1 @ zone.js:379drainMicroTaskQueue @ zone.js:386 error_handler.js:52 Error: Uncaught (in promise): Error: Error in ./Login class Login_Host - inline template:0:0 caused by: No provider for UserData!

答えて

0

エラーメッセージはそれをすべて言う:No provider for UserData!provideにあなたが必要

あなたののUserDataサービスはこのように、providersアレイを使用して:

@NgModule({ 
    imports: [ 
     BrowserModule, 
    ], 
    declarations: [ 
     AppComponent 
    ], 
    providers: [ 
     UserData 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
0

を使用すると、プロバイダの配列に、NgModule内のUserDataを登録したことがありますか?

関連する問題