These are chat archives for angular/angular.js

Jan 2017
Jan 21 2017 08:13
I want to create elements on HTML page. I want to know that which of the following approach is better and why:
  1. Creating all the elements on HTML page individually. (Static code)
  2. Creating elements with ng-repeat.
I know the total number of elements that i have to create. But each element have at least 1 dynamic value.
Ayush Bahuguna
Jan 21 2017 10:28
@GhanghasChirag_twitter just a friendly reminder that, each directive creates a watcher which in turn creates a digest loop. If you have too many digest loops then your website may slow down, no, it will slow down. if the value depends upon user input, and changes based on the user input, then you'd use angular directives(in this case ng-repeat), but if the value doesn't depend on user input then you are better off with hard coding the elements.
George Kalpakas
Jan 21 2017 11:36

each directive creates a watcher

@relentless-coder, that is not true. (Although ngRepeat may create one, most directives don't).
If the array is static, you can use one-time bindings which don't create a watcher.

which in turn creates a digest loop

also, not true. It possibly creates a watcher. The number of digests won't change - only the number of watchers checked during each digest.

If you have too many digest loops then your website may slow down, no, it will slow down.

I assume you meant to say "too many watchers". It definitely doesn't help to have many of them, but what is more important is how "heavy" they are. 10000 super-light watchers are faster than 100 slow ones. So, it depends.

@GhanghasChirag_twitter: I would use ngRepeat with a one-time binding. The only drawback of this vs hard-coding the elements is that there is slight initial setup cost. In most cases this is neglible (unless you have a very long array). If you are too concerned about the initial rendering speed and you find the cost to be noticeable, hard-code the elements. (In most apps, it won't be an issue.)
Jan 21 2017 13:40
Angular 2
Abide Masaraure
Jan 21 2017 21:35
Hi angular 1 gitters. I used this patch derived from this fiddle to load directives dynamically in our angular 1 app. It works in all browsers but ng-show is then rendered useless in IE 11 showing null for evaluated expressions. Any idea how i can appease IE
George Kalpakas
Jan 21 2017 21:55
From a superficial look, I would try to replace element.html(null); with element.html(''); inside the destroyInnerElement() method of DynamicDirectiveContext.
^ @abidmix