Reputation: 316
imagine we have a server that sometimes tell us show some dialogs for confirmation.
I actually think I have to show dialog from service but in angular doesn't have this ability.
how can implement this?
Upvotes: 1
Views: 2729
Reputation: 86800
Basically as already said by @pranav Services are used to share data between controller and to perform diff actions, you must have to send some flag in this case status code (which i assume is proficient) than accordingly you can show some dialog/alert or whatever you want to show.
how to show dialog in service in angular 2
if you still want to show dialog/popup from your service you have to use some third party library, here i am using toaster
in this,
you can call this toaster from anywhere whether it is from function/button click or form service you juts have to add
js and css file of toaster.
here is working demo of the same
PS: you also can use growl from primeng if you want to call dialog from your controller, see here
Upvotes: 1
Reputation: 1076
Angular services are specifically built for sharing the data between different controllers & to implement the generic functions.
The best way is to take response from the server, pass response to the controller & on the basis of response (i.e. true/false) show the dialog.
Reference how to use angular 2 modal: https://github.com/shlomiassaf/angular2-modal
Upvotes: 1