angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular component lifecycle hooks are not called when a new component is navigated in the callback of async fs.writeFile

Open prabhanjan2906 opened this issue 9 years ago • 2 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.1.0 node: 6.11.0 os: win32 x64 @angular/animations: 4.4.4 @angular/common: 4.4.4 @angular/compiler: 4.4.4 @angular/core: 4.4.4 @angular/forms: 4.4.4 @angular/http: 4.4.4 @angular/material: 2.0.0-beta.12 @angular/platform-browser: 4.4.4 @angular/platform-browser-dynamic: 4.4.4 @angular/router: 4.4.4 @angular/cli: 1.1.0 @angular/compiler-cli: 4.4.4 @angular/language-service: 4.4.4 @electron: 1.7.8

Repro steps.

@component({ template: <button name="buttonName" id="buttonID" (click)="**saveFileAndGotoNextPage**()"> click me!</button> }) export class myComponentA{ saveFileAndGotoNextPage() { fs.writeFile(myFileName, "any data", (err) => { if(err){ throw err; } else{ this.router.navigate['/nextRoute']; // Routing inside the async filewrite callback } } } }

@component({ .... }) export class myComponentB implements OnInit, AfterViewInit, OnChanges,OnDestroy { constructor(){ console.log("constructor was called"); }

ngOnInit(){ console.log("ngOnInit was not called"); }

ngAfterViewInit(){ console.log("ngAfterViewInit was not called"); }

ngOnChanges(){ console.log("ngOnChanges was not called"); }

ngOnDestroy(){ console.log("ngOnDestroy was not called"); } }

-------------------- This works -------------------- @component({ template: <button name="buttonName" id="buttonID" (click)="saveFileAndGotoNextPage()"> click me!</button> }) export class myComponentA{ saveFileAndGotoNextPage() { this.router.navigate['/nextRoute']; //I Called it outside the callback } }

@component({ .... }) export class myComponentB implements OnInit, AfterViewInit, OnChanges,OnDestroy { constructor(){ console.log("constructor was called"); }

ngOnInit(){ console.log("ngOnInit was called"); }

ngAfterViewInit(){ console.log("ngAfterViewInit was called"); }

ngOnChanges(){ console.log("ngOnChanges was called"); }

ngOnDestroy(){ console.log("ngOnDestroy was called"); } }

The log given by the failure.

I find a warning message on the console that says, [Violation] 'click' handler took 2577ms

Desired functionality.

life cycle methods get called when the new route is navigated inside the async writeFile() Callback

Mention any other details that might be useful.

prabhanjan2906 avatar Oct 09 '17 20:10 prabhanjan2906

Hi @prabhanjan2906,

This is outside the scope of the Angular CLI. We do not support building and running Electron apps. Maybe Stack Overflow would be a better place to get this kind of support.

BTW, we've seen problems in Universal with Zone.js and some streaming APIs. Maybe there's something to it, maybe not.

Closing this as this is not within the supported scope of the CLI.

hansl avatar Oct 12 '17 00:10 hansl

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.