Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling OK, but Angular doesn't render changes #391

Closed
aletaschner opened this issue Sep 24, 2019 · 3 comments
Closed

Compiling OK, but Angular doesn't render changes #391

aletaschner opened this issue Sep 24, 2019 · 3 comments
Labels

Comments

@aletaschner
Copy link

I'm a little bit confused by a simple test I've made and it seems like Angular doesn't render changes on the screen. I have made a simple code to show.

On home.component.ts

loaded = false;
  ngOnInit() {
    this.electron.ipcRenderer.send('started', true);
    this.electron.ipcRenderer.on('loaded', (e) => {
      console.log('received "loaded" from main');
      this.loaded = true;
      window.setTimeout(() => console.log(this.loaded), 2000);
    });
  }

home.component.html

<div class="container" *ngIf="loaded">
  <h1 class="title">
    {{ 'PAGES.HOME.TITLE' | translate }}
  </h1>
</div>
<div *ngIf="!loaded" class="container">
  <h1 class="title">
    Loading...
  </h1>
</div>

main.ts (inside createWindow function)

ipcMain.on('started', (e) => {
    console.log('received "started" from window');
    setTimeout(() => {
      console.log('few seconds later, sendind loaded to window');
      win.send('loaded', ":D");
    }, 3000);
  });

Even when checking the logs, everything seems to work out great:
node console:
image
dev tools console:
image

Yet, what I get on screen is the "loading..." text and it does not refresh.

Am I doing something wrong?

Thanks in advance!

@txtcbenne
Copy link

I've had this issue before as well. I solved it by injecting ChangeDetectorRef and detecting the changes after the data was changed. In your case:

  loaded = false;
  constructor(private electronService: ElectronService, private change: ChangeDetectorRef) { }
  ngOnInit() {
    this.electron.ipcRenderer.send('started', true);
    this.electron.ipcRenderer.on('loaded', (e) => {
      console.log('received "loaded" from main');
      this.loaded = true;
      this.change.detectChanges()
      window.setTimeout(() => console.log(this.loaded), 2000);
    });
  }

@aletaschner
Copy link
Author

Great! This actually worked. Thank you very much.

Althought it would be great to know why it doesn't simply work, this already helps me a lot!

@stale
Copy link

stale bot commented Oct 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 24, 2019
@stale stale bot closed this as completed Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants