Check If An Angular Directive Exists
We're doing a lot of work around dynamic directives in our Angular project, and one thing that came up as a nice-to-have was a way to have a generic directive that can list many di
Solution 1:
You can use $injector.has
to check if a provider or instance exists.
app.directive('objectList', function ($compile, $injector) {
return {
template: 'OK',
link: function (scope, element, attrs) {
var exist = $injector.has('myMessageDirective');
...
}
};
});
Post a Comment for "Check If An Angular Directive Exists"