I have an small Angular 2 app that fetches the data from ASP.net MVC Web API. Using Authentication. I am trying to use Ahead Of Time compiler in Angular 2. I am running the following command
node_modules \ .bin\ngc -p src
but i am getting following error
(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.
can some one tell me how to resolve it
This is my directory structure
I have move the tsconfig.json from root to src folder as it was directed in this link
That's how i am using promise
I have made services from which i return the promise like this:
public get(servicename: string) {
this.colorlog.log('get ' + servicename + " ",enmMessageType.Info);
return this.http.get(this.ngWEBAPISettings.apiServiceBaseUri + "api/" + servicename + "/", this.ngWEBAPISettings.getConfig()).toPromise();
}
and consuming it in component like this
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);
});
}
this is my ts.config file.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
I have accomplish this in following steps
First
I have updated the version as mentioned by MrJSingh
After updateh package.json dependencies section become like this.
Second
After that i have made changes to app.module.ts file and change useValue to useFactory
change this
to this
Finally command runs successfully after these two steps.
For Latest version use declaracions instead of providers
For more detail check this link