2016-12-29 115 views
3

我有一個小的Angular 2應用程序,它從ASP.net MVC Web API中獲取數據。使用認證。我試圖用提前在角2.時間編譯器,我運行以下命令未處理的承諾拒絕AOT(提前)Angular 2

node_modules \ .bin\ngc -p src

但我得到以下錯誤

(node:13640) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Right-hand side of 'instanceof' is not an object (node:13640) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

可以有一個人告訴我如何解決它

This is my directory structure

我有移動tsconfig.json從根到src文件夾,因爲它是在這個link

執導

Directory structure

That's how i am using promise

我已經做服務,從我返回的承諾是這樣的:

public get(servicename: string) { 
    this.colorlog.log('get ' + servicename + " ",enmMessageType.Info); 
    return this.http.get(this.ngWEBAPISettings.apiServiceBaseUri + "api/" + servicename + "/", this.ngWEBAPISettings.getConfig()).toPromise(); 
} 

像這樣

get() { 
    var promise = this.setupServicePromise.get(this.SERVICE_NAME); 

    promise.then((response: any) => { 
     this.colorlog.log('in then promise ProductComponent get' + response, enmMessageType.Data); 
     this.vm.Products = response.json(); 
    }).catch((error: any) => { 
     this.colorlog.log("Error Occurred in product", enmMessageType.Error); 
    }); 
} 

消費它的成分,這是我的TS .config文件。

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": ["es2015", "dom"], 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true 
    } 
} 
+1

你可以分享你tsconfig文件? –

+0

請檢查問題 – rashfmnb

+1

我有這個問題,我通過更新我的角度來更新我的角度2.4.1,我的意思是角/核心,通用,窗體,編譯器,編譯器CLI。試試這個 –

回答

1

我在下面的步驟

首先做到這一點

提到MrJSingh

後updateh 的package.json依賴性節成爲我已經更新了版本喜歡這個。

"dependencies": { 
    "@angular/common": "~2.4.0", 
    "@angular/compiler": "~2.4.0", 
    "@angular/compiler-cli": "^2.4.1", 
    "@angular/core": "~2.4.0", 
    "@angular/forms": "~2.4.0", 
    "@angular/http": "~2.4.0", 
    "@angular/platform-browser": "~2.4.0", 
    "@angular/platform-browser-dynamic": "~2.4.0", 
    "@angular/router": "~3.4.0", 
    "core-js": "^2.4.1", 
    "rxjs": "5.0.1", 
    "zone.js": "^0.7.4" 
}, 

之後,我已經修改了app.module.ts文件,並更改useValueuseFactory

改變這種

let authService = new AuthService(new LocalStorage()); 
providers: [ 
    {provide:AuthService,useValue:authService}, 
    AdminAuthGuard, 
    UserAuthGuard, 
    SetupServicePromise, 
    SetupServiceObservables 
] 

至此

export function authServiceFactory() { 
    return new AuthService(new LocalStoragee()); 
} 

providers: [ 
    {provide:AuthService,useFactory:authServiceFactory}, 
    AdminAuthGuard, 
    UserAuthGuard, 
    WebAPISettings, 
    LoginService, 
    SetupServicePromise, 
    SetupServiceObservables 
] 

最後命令在這兩個步驟後成功運行。

Note

對於最新版本使用declaracions,而不是供應商

declarations: [ 
    {provide:AuthService,useFactory:authServiceFactory}, 
    AdminAuthGuard, 
    UserAuthGuard, 
    WebAPISettings, 
    LoginService, 
    SetupServicePromise, 
    SetupServiceObservables 
] 

對於更詳細檢查此link

+1

在這幾個星期裏,角模塊沒有提供者,而是有聲明。 – peterh

+0

感謝您更新了它。 – rashfmnb

相關問題