未处理的承诺拒绝AOT(提前)Angular 2
我有一个小的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
执导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
}
}
我在下面的步骤
首先做到这一点
由提到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文件,并更改useValue到useFactory
改变这种
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
你可以分享你tsconfig文件? –
请检查问题 – rashfmnb
我有这个问题,我通过更新我的角度来更新我的角度2.4.1,我的意思是角/核心,通用,窗体,编译器,编译器CLI。试试这个 –