JavaScript How to force update of ng-init ? update-initramfs force

I found that ng-init is not updated after rowIndex is updated.

<div ng-init="item = getItem(rowIndex)">
   {{ item.Name }} 
</div>

item is not updated after rowIndex is changed (even if changes are made with $timeout)

Is there other directive that allows to avoid using the following dirty trick:

<div ng-repeat="item in [getItem(rowIndex)]">
   {{ item.Name }} 
</div>
Answer:1

Another approach is to set the variable inside a bogus attribute:

<div x="{{item = getItem(rowIndex)}}">
    {{ item.Name }} {{item.Value}}
</div>

On each digest cycle the value of item will be updated.

In this case where item has more that one property, the getItem function needs to be invoked only once.

Keep in mind that it would be even more efficient for the controller to update the value of item only once when rowIndex changes instead of invoking the getItem function every digest cycle.


Avoid using ng-init

Avoid using ng-init. It tangles the Model and View, making code difficult to understand, test, debug, and maintain. Instead initialize the Model in the controller.

From the Docs:

ngInit

This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit, such as for aliasing special properties of ngRepeat, as seen in the demo below; and for injecting data via server side scripting. Besides these few cases, you should use controllers rather than ngInit to initialize values on a scope.

— AngularJS ng-init Directive API Reference

Answer:2

ngInit does not update. It's a one-shot directive. You should just call the function from within the curly braces, since you are wanting to watch for changes to rowIndex:

<div>
  {{ getItem(rowIndex).Name }}
</div>

This could hurt performance on large lists, since getItem will be called on every digest cycle, but it's easy to read.

https://plnkr.co/edit/cZ2SG6nf2SufdAWe1ye7?p=preview

Answer:3

I am in process of researching how to measure the performance metrics of an Angular JS applications. I have following questions. Please share your thoughts. Angular JS suits well for one page ...

I am in process of researching how to measure the performance metrics of an Angular JS applications. I have following questions. Please share your thoughts. Angular JS suits well for one page ...

  1. measure performance angular
  2. measure performance angular 2
  3. measure performance angular 4

I bumped into a few statements from people that "let blocks and let expressions are obsolete" in SpiderMonkey, while there's very little information about it. I'm wondering what does this exactly mean?...

I bumped into a few statements from people that "let blocks and let expressions are obsolete" in SpiderMonkey, while there's very little information about it. I'm wondering what does this exactly mean?...

  1. what does this emoji mean
  2. what does this mean �� ��
  3. what does this symbol mean
  4. what does this emoji mean ��
  5. what does this sign mean
  6. what does this mean in english
  7. what does this word mean
  8. what does this emoji mean ��
  9. what does this emoji mean ��
  10. what does this emoji mean ��
  11. what does this emoji mean ��
  12. what does this mean in texting
  13. what does this national emergency mean
  14. what does this emoji mean ��
  15. what does this symbol mean in math
  16. what does this quote mean
  17. what does this mean in spanish
  18. what does this mean in math
  19. what does this mean 3
  20. what does this emoji mean ��

I am working on an html page where i have div element and also a inner div element. In the inner div element there is a image element. The main and inner div are 2 in numbers. <div class="owl-...

I am working on an html page where i have div element and also a inner div element. In the inner div element there is a image element. The main and inner div are 2 in numbers. <div class="owl-...

  1. find image inside another image python
  2. find image inside another image
  3. find image inside div jquery
  4. find image inside image
  5. jquery find image inside anchor
  6. find image inside another image java
  7. find image inside another image c#
  8. opencv find image inside image
  9. c# find image inside image
  10. java find image inside image

I have this code: v.d = new Date().toLocaleTimeString(); it yields something like this: 20:11:40 So this is the time of day to the second, without milliseconds. My question is: is there a built in ...

I have this code: v.d = new Date().toLocaleTimeString(); it yields something like this: 20:11:40 So this is the time of day to the second, without milliseconds. My question is: is there a built in ...

  1. millis using arduino uno