0

I have started leaning AngularJS.

In AngularJS if we have to initialize an element lets take an example of select:

<select id="s1" ng-model="vsrc" ng-init="vsrc='a.mp4'">
    <option value="a.mp4">First video</option>
    <option value="b.mp4">Second video</option>
</select>

why initialization of vsrc='a.mp4' in ng-init is required, when I was giving its value like ng-init='a.mp4' it was not working I had to give like ng-init="vsrc='a.mp4'". In normal HTML statement we are directly giving default option by providing value='a.mp4'

miquelarranz
  • 876
  • 11
  • 26
Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • Because ngInit expects expressions that are evaluated, as every other expression, on the scope. It has nothing to do with ng-model. You should (almost) never use ngInit. Read the documentation: https://docs.angularjs.org/api/ng/directive/ngInit – JB Nizet Jun 15 '16 at 11:35

1 Answers1

0
<select id="s1" ng-model="vsrc" ng-init="vsrc='a.mp4'"> /*ng-init used to initialize a **variable** before html render, it is a directive which search left and right value always*/
<option value="a.mp4">First video</option> /*value is here as json object {"value":"a.mp4"}*/
<option value="b.mp4">Second video</option>
</select>

take a look over here about ng-init directive

Shrikant
  • 538
  • 5
  • 15