Thursday, 9 March 2017

How to enable AngularJS in HTML ?


Whenever you want to use angular expression, just use ng-app attribute with that specific tag (html, div, form etc.)

<html> <head>
    <script type="text/javascript" src="angular.min.js"> </script>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
  <div ng-app>
          10+20 = {{ 10 + 20 }}

    <br>
    {{ 1 == 2 }}
    <br>
    {{ {name: 'Shaan', age: '30'}.name }}

    <br>
    {{ ['Shaan', 'Rahul', 'Sattu'][2] }}
  </div> </body>

Output
10+20 = 30
false
Shaan
Sattu

In order to use AngularJS in whole of the page, you can use ng-app with html tag.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.