Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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'

share|improve this question
    
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: docs.angularjs.org/api/ng/directive/ngInit – JB Nizet Jun 15 at 11:35
<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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.