2017-12-26 14 views
1

私はAngular 4.4.6バージョンを使用したプロジェクトを持っています。 this is version of angular角度4で待っているときジェネレータが定義されていないエラー

設定して実行しても大丈夫です。しかし、非同期を使用するときに問題があり、機能をonSubmitログインで待つ:login.component.ts:

public async onSubmit() { 
    this.submitted = true; 
    if (this.form.valid) { 
     const user: ILoginUser = { 
     UserName: this.form.value.username, 
     Password: this.form.value.password 
     }; 
     this.isLoginSuccessful = await this._loginService.login(user, true); 
    } 
    } 

私はなぜスロー例外exception here知りません。私はtsconfig.jsonの問題だと思っていますが、私はちょうど私が間違っている位置を知らない。

これはtsconfig.jsonです:

{ 
    "compileOnSave": false, 
    "compilerOptions": { 
    "outDir": "./dist/out-tsc", 
    "baseUrl": "src", 
    "sourceMap": true, 
    "declaration": false, 
    "moduleResolution": "node", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "noEmit": true, 
    "noEmitHelpers": false, 
    "target": "es5", 
    "typeRoots": [ 
     "node_modules/@types" 
    ], 
    "lib": [ 
     "es2016", 
     "dom" 
    ], 
    "plugins": [ 
     { 
     "name": "tslint-language-service" 
     } 
    ] 
    }, 
    "exclude": [ 
    "node_modules", 
    "dist" 
    ], 
    "awesomeTypescriptLoaderOptions": { 
    "forkChecker": true, 
    "useWebpackText": true 
    }, 
    "buildOnSave": false, 
    "atom": { 
    "rewriteTsconfig": false 
    } 
} 

Everyone please help me, many thanks! 

答えて

0

私は非同期を使用する代わりに、購読して待つ使用することをアドバイスします。あなたがこれに何らかの誤りがあった場合は、私に知らせてください。

ログイン機能が観測を返すされなければならない時に使用しなければならない場合は、約束して、観察を変換したい場合がありますので

は、約束のために作品を待つように待っています:
は>>(.loginファイルをお待ちしており,, ).toPromise()

public onSubmit() { 
 
    this.submitted = true; 
 
    if (this.form.valid) { 
 
    const user: ILoginUser = { 
 
     UserName: this.form.value.username, 
 
     Password: this.form.value.password 
 
    }; 
 
    this._loginService.login(user, true).subscribe((bool) => { 
 
     this.isLoginSuccessful = bool; 
 
    }); 
 
    } 
 
}

+0

うん、私はinsteaを購読使用に変わると思いdは非同期で待機します。 角の新しいバージョンは、より多くの購読をサポートします。 – vuvietkien

+0

async awaitは購読と同じexacltyではありませんが、購読中にコードを待つことはありません。 –

+0

確かに、アングル4の購読についてもっと知る必要があります。 おかげさしでありがとうございます! – vuvietkien

関連する問題