AngularJS Trigger directive from controller call

I want to trigger an AngularJS custom directive that contains jQuery instructions. How can it be done? I have read about emit function in the directive?



You can use a service to communicate between the controller and the directive.

Service might look like this:

app.service("directiveService", function() {
    var listeners = [];
    return {
        subscribe: function(callback) {
        publish: function(msg) {
            angular.forEach(listeners, function(value, key) {

And the directive could respond to the service:

app.directive("jQueryDirective", function(directiveService) {
    directiveService.subscribe(function(msg) {
        // pretend this is jQuery 
        .innerHTML = msg;
    return {
        restrict: 'E'        

Just substitute what I did for jQuery manipulation and you should have what you need.

Here's a working fiddle:

Need Your Help

Sinhala Unicode rendering issues in Java Swing

java swing unicode

When I use Sinhala Unicode word "ප්‍රවාහන" in JLabel it renders as "ප්රවාහන".

Start process from System Account with a specific User Name

c# .net windows-services process

I'm developing a windows service in, Account: LocalSystem, System: Windows XP SP3