Hello. I just try to show toast message in Service class.
Like ,
nodeService.getTreeNodes().then(data => setNodes(data));
and if i got error in class method i want to show toaster with error message. could i do that?
getTreeTableNodes() {
return fetch('data/treetablenodes.json').then(res => res.json())
.then(d => d.root).catch(error= { toaster.show("error message")});
}
Toast in class service
You have to have a REF to your Toaster and I don't see that in your code above.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Posts: 10
- Joined: 11 Nov 2020, 15:19
YEah you will have to pass a ref to your TOAST into your service method like...
Code: Select all
getProduct(toast: Toast) {...
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Posts: 10
- Joined: 11 Nov 2020, 15:19
that worked. Thank you.
So can I access the context inside the service class? i dont want to pass toast parameter in all methods.
i put my toast ref to context; like : <AuthContext.Provider value={{toast,
So can I access the context inside the service class? i dont want to pass toast parameter in all methods.
i put my toast ref to context; like : <AuthContext.Provider value={{toast,
Yep that would be your other option. You just need some reference to it.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests