Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

ipcRenderer.on issue #2

Closed
abhargav7 opened this issue Mar 24, 2017 · 10 comments
Closed

ipcRenderer.on issue #2

abhargav7 opened this issue Mar 24, 2017 · 10 comments
Labels

Comments

@abhargav7
Copy link

I have successfully integrated this package and able to listen to click on menu items in angular2 components. But the issue is I cannot bind the functions properly inside it suppose I try to update some text inside the text box or change the bool value it does not work, however when I do a console.log("function is hit") it appears in electron devtoogle window, but values are not assigned.

this._ngZone.run(() => { _electronService.ipcRenderer.on('open-file', this.enableError.bind(this));
enableError()
{
console.log("function is hit");
this.something= true/false it does not work
}

@ThorstenHans
Copy link
Owner

ThorstenHans commented Mar 24, 2017

instead of using

this._ngZone.run(() => { _electronService.ipcRenderer.on('open-file', this.enableError.bind(this));
enableError()
{
console.log("function is hit");
this.something= true/false it does not work
}

I would do

_electronService.ipcRenderer.on('open-file', this.enableError.bind(this));

enableError(){
   this._ngZone.run(()=> {
     console.log("function is hit");
     this.something= true; ///false it does not work
   });
}

I think with your implementation, the callback is not invoked inside of angular, just the submission of the ipc message runs inside of Angular. Which is also true, without ngZone

@ThorstenHans ThorstenHans self-assigned this Mar 24, 2017
@abhargav7
Copy link
Author

Thanks for a quick help. I tried your suggestion still facing the issue, however i also remove this._ngZone.run(()=> from all the places I still not able to execute the calls in angular, however console prints just fine.

@ThorstenHans
Copy link
Owner

console.log will work fine, because it's not related to angular at all.

if you call it like

this._electronService.ipcRenderer.on('open-file', ()=> {
    this.enableError();
});

it should work.

But if you want to update bound data in angular templates, you've to ensure ngZone is used to tell angular that the execution from outside angular has finished. in this case, setting the bound value on your component class has to be inside of ngZone...

@abhargav7
Copy link
Author

Hmm OK, do you have some sample code to help me understand this logic better?

But if you want to update bound data in angular templates, you've to ensure ngZone is used to tell angular that the execution from outside angular has finished. in this case, setting the bound value on your component class has to be inside of ngZone...

@ThorstenHans
Copy link
Owner

during the weekendm I'll create a short example using node.js fs module. looks like you're trying to read a file from the harddisk and show something depending on the file existance or it's content, right

@abhargav7
Copy link
Author

no actually I am trying to do a bool visibility of some control hide/unhide in angular component from electron menubar

@ThorstenHans
Copy link
Owner

ahh i see, so you are using browserWindow.webContents.send from the main proc and want the angular app to "react" 🤣 (let the angular app react :D) - sorry it's friday - on the message

@abhargav7
Copy link
Author

abhargav7 commented Mar 24, 2017

👍 correct :)

@ThorstenHans
Copy link
Owner

@abhargav7 I've updated the example at https://github.com/ThorstenHans/electron-ngx-sample there is a button in the menu which toggles the notify button on the kittendetails component.

HTH 🤘

@ThorstenHans ThorstenHans removed their assignment Mar 25, 2017
@ThorstenHans
Copy link
Owner

closing this one. @abhargav7 If you've further question feel free to open another issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants