AngularJS | ng-init Directive

The ng-init directive is used to initialize an AngularJS Application data. It defines the initial value for an AngularJS application and assigns values to the variables.
The ng-init directive defines initial values and variables for an AngularJS application.

Syntax:

<element ng-init = "expression">
   ...
</element>

Example: In this example, we initialize an array of string.



filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
    angular.min.js"></script>
    <head>
        <title>AngularJS ng-init Directive</title>
    </head>
    <body>
            <h1 style = "color:green">GeeksforGeeks
            <h2>ng-init directive</h2>
            <div ng-app="" ng-init="sort=['quick sort', 'merge sort',
             'bubble sort']">
             Sorting techniques:
            <ul>
            <li>{{ sort[0] }} </li>
            <li>{{ sort[1] }} </li>
            <li>{{ sort[2] }} </li>
            </ul>
         </div>
    </body>
</html>

chevron_right


Output:
ng-app



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.