View Angular 1 directive dependency/hierarchy - angularjs

Is there a tool or some way to view the hierarchy use of directives in your html templates? Something like react-component-hierarchy but for angular. Or maybe AngularJSGraph but showing directives pointing to other directives that use them

Related

Angular UI Bootstrap scope variables in custom typeahead template

I am using UI Bootstrap's typeahead directive, and added my own popup template via typeahead-popup-template-url. In that template, I'd like to access scope variables from the parent template (i.e. the one in which I've used the typeahead directive). Is this possible?
Here's a (broken) example of what I'm trying to do ("hello" should be present in the dropdown): http://plnkr.co/edit/ITT1SdRfUWeeN6n3aMqu?p=preview
I'd like to do this WITHOUT modifying the typeahead directive. I don't want to muck around in third party (uib) code if there's a more elegant solution.
In your template, you need to reference the $parent scope. Change:
This should say "hello": {{hello}}</h1>
To:
This should say "hello": {{$parent.hello}}</h1>
Bootstrap, jquery ui, kendoui, yui etc
Isn't that a bit much of frameworks together O.o
Anyway this post might help: How to access parent scope from within a custom directive *with own scope* in AngularJS?

Angular directive loading order

I am using Packery in a directive as in the example here
Packery angular directive
enter code here
I am also creating dynamic elements as described here angular dynamic templates
in which I wish to apply the directive to however I believe the packery directive is loaded before the dynamic template gallery so the new content is not working with packery , I am looking for a way to ensure the dynamic content works with the packery directive

Not sure when to use ng-view or ng-include

I have used recently the ng-view in partial view and it looks much like the use of ng-include. Is there a difference between the two: ng-view directive and ng-include or when is it better to use which?
Basicly ng-View creates a new View which works with States or Routing, saying this view gets his own Controller and Stuff like it would be a html file. And ng-include is if you have like a html template which u need to show on different views and include it to not duplicate code.
So for example you can ng-include your header html where you have your navigation, and you could ng-view a register form or smth where you need it to have its own Route/ State and Controller

AngularJS: Where to store my CSS related to a directive?

Assume that you want to create a directive in AngularJS that requires an external CSS file.
Are there any best practices on where to store the directive's CSS content?
Edit : I am after a solution that in order to copy my directive to another anguarljs app, I will only need to copy the directive code and not have to go over all my CSS.
In the case where there is a templateUrl parameter in the directive, I guess the best place to put the directive's CSS is the HTML template, or not?
If you keep the html template in a separate file I would suggest you keep the css separately too. In this case you could use a tool like grunt or gulp to bring all those separate directive css together
If the html template is inside the directives definition the best choice would be to keep the css as a style tag provided that the style sheet is a must have and is as malleable as possible

Angularjs directive + do I need to $compile

I'm in need of some pointers in my landingPage-builder project. (i'm currently stuck!).
The main issue is as follows:
Each element in the template (like the h1 and the paragraph) has attached a directive. What I need to get the directive to do is: create a template of HTML with some other directives attached like ng-click, ng-options etc, keep the bindings to the model intact (currently far away from working), update the model when changed.
I'm not trying to append to, or replace the element the directive is on, but make a html-template and inserting it into the DOM (almost like another view) so that the model on the left can be updated from the "settings" box on the right.
The project can be viewed here: http://193.107.29.196/~stian123/landingPageV3/app/#/pagebuilder/2
You may need Allow-Control-Allow-Origin for Chrome: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related
I'm a bit confused about $compile and doesn't really know when I need to use this part of the directives api.
Any suggestions?
Thank you!
If I understood your question correctly, you want to dynamically create templates, some of which have Angular attributes in them, then attach them to the DOM.
First, to (hopefully) answer your question, about when to call $compile:
Whenever you load in HTML from outside Angular's template system (like trying to set $(element).html(myHtmlString)), you need to let Angular compile it before you attach it to the DOM. In other words:
elem.append($compile(yourHTMLString)(scope));
This lets Angular traverse the DOM and parse any directives and bindings and attach them to the provided scope. If you don't $compile, Angular has no idea about those intended bindings at all, the HTML is never read by Angular.
Second, I don't know how flexible you want your templates to be, but if they're relatively fixed, but with some fixed customizable options (text, color, font-size etc), you might be better off creating a directive for each 'view', with the view options bound to the scope of the directive. Then you can just change the fields on the scope of the directive in the panel on the right side, and the view will update directly. You wouldn't even have to use $compile in this case.
If you want the user to be able to manually add the template HTML code, you will have to compile the HTML as described above.

Resources