Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if an Angular directive exists
    primarykey
    data
    text
    <p>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 different types of similar objects (e.g., messages, users, comments, etc.), by delegating to specific directives based on the objects' types.</p> <p>We call this directive, <code>object-list</code> and it will hopefully delegate to a number of different directives, if we can get it working properly.</p> <p>The main issue we need to tackle is whether or not a directive that this <code>object-list</code> directive has been provided exists in our system. The way we've been checking this is by issuing a <code>$compile</code> against the target directive, linking it to a scope, and checking its HTML contents (e.g., <code>var tmpElement = $compile('&lt;div my-message'&gt;&lt;/div&gt;')(scope);</code>). This seems to work when the template for the target directive is referenced by the <code>template</code> option, but when we instead try to point to a <code>templateUrl</code>, the HTML contents are empty.</p> <p>Here's a Plunker, with the <code>templateUrl</code> approach in place (not working). You can comment it out and uncomment the <code>template</code> line to see the alert show up.</p> <p><a href="http://plnkr.co/edit/wD4ZspbGSo68v4eRViTp">http://plnkr.co/edit/wD4ZspbGSo68v4eRViTp</a></p> <p>Is there another way to check the existence of a directive? I'll admit, this does seem a bit of a hack.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload