How can I call some directive from Controller after success ajax request?
For example if I have function:
function successAjax()
{
call directive
}
and if I have in template:
<directive></directive>
there should appear:
<p>success</p>
How can I call some directive from Controller after success ajax request? For example if I have function:
and if I have in template:
there should appear:
|
|||||
|
You have a few choices to go the way you want. If I were you, I would instead move your AJAX call into your directive to sidestep the issue entirely (even better: move the AJAX call to a service that gets injected into the directive):
If you absolutely have to have the AJAX call in your controller, you can use events, but you should be sparing with these as they will clog up the digest loop:
Another option you have is to bind some data from the controller to your directive:
|
|||||||||||||||||
|
You should create another service, on which you will set a value to notify that the request has been completed. Then in your directive, you'll watch over the variable in that service and display the message in your directive's template with |
|||
|
First i don't feel any need of showing success message after ajax call using directive. Angularjs has used $q service to deal with http calls and return promise object and handle that in your controller, after that you can bind the success message to your view from controller scope. If you want to trigger directive from controller your can use $broadcast to send event to entire $rootScope and handle that in your directive. Example:
In Directive:
This would be hopefully help you. Thanks. |
|||||
|