-1

I am watching a video to learn angularjs. I used CDN link for including angularJs

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"/>
    </head>
    <body ng-init="names=['shan', 'amit', 'vaibhav']">
        <ul>
            <li ng-repeat="pname in names">
            {{pname}}
            </li>
        </ul>
    </body>
</html>

I have no other file. That's the simplest piece of code I have and on browser I see blank page. What's wrong in this?

Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286

5 Answers5

5

Fix the script line:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
jwatts1980
  • 7,254
  • 2
  • 28
  • 44
5

Put an ng-app attribute on the html tag:

<html ng-app>

And close your script tag (it's not self-closing)

http://jsfiddle.net/g02ket0t/

tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • curious to know, why `ng-app` is required? Is it something angularJs framework searches to initialize angularJs script? – Shantanu Gupta Jun 04 '15 at 20:41
  • @ShantanuGupta -- Yes, it's required to bootstrap the app – tymeJV Jun 04 '15 at 20:44
  • I don't understand why people keep posting duplicate answers even after looking that all of their points have been covered in one answer :(. I wish there could have been a way to close those answers. – Shantanu Gupta Jun 04 '15 at 20:47
-2

You can also use data-ng-, instead of ng-, if you want to make your page HTML valid.

<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js">
</script>
</head>
<body>
    <div data-ng-init="names=['shan', 'amit', 'vaibhav']">
        <ul>
            <li data-ng-repeat="pname in names">{{pname}}</li>
        </ul>
    </div>
</body>
</html>
Thomas Weglinski
  • 1,094
  • 1
  • 10
  • 21
-2

You're missing the closing tag. Also add the ng-app attribute in the html tag to link to your app.

Marco V
  • 2,553
  • 8
  • 36
  • 58
-2
  • Complete Script tag
  • Use ng-app attribute.

  <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    </head>
    <body ng-app ng-init="names=['shan', 'amit', 'vaibhav']">
        <ul>
            <li ng-repeat="pname in names">
            {{pname}}
            </li>
        </ul>
    </body>
</html>
Johney
  • 87
  • 6