0

I am trying to open dialogs, which have their own Controllers, opening them through events. My problem now is, that I am always getting

Cannot read property $emit of undefined`, because for some reason my $rootScope is undefined.

How can I inject the $rootScope properly?

I am using Angular 1.6.7.

.directive("opendialog", [function($rootScope) {
  return {
    link: function(scope, element, attributes) {
      element.bind("click", function(event) {
        var dialogId = $(element).attr("id");
        $rootScope.$emit(dialogId, {
          command: "open"
        });
      });
    }
  }
}]);

1 Answer 1

1

Try this

.directive("opendialog", ["$rootScope", function ($rootScope) {
return {
    link: function (scope, element, attributes) {
        element.bind("click", function (event) {
            var dialogId = $(element).attr("id");
            $rootScope.$emit(dialogId, {command: "open"});
        });
    }
}
}]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.