1

I am a new learner of Angular JS. Please help me to find reason why this demo only display : {{name}} instead of showing each values,

 <!DOCTYPE html>
<html>
    <head>
        <title>AngularJS Demos</title> 
    </head>
    <body> 
        <div class="container" data-ng-app="demoApp" data-ng-controller="SimpleController">
            <h3>Adding a Simple Controller</h3>
            <ul>
                <li data-ng-repeat="name in names">{{name}}</li>
            </ul>
        </div> 
        <script  type="text/javascript">
            var samplesModule = angular.module('demoApp', []); 
            samplesModule.controller('SimpleController', SimpleController);
            function SimpleController($scope) {
                $scope.names = ['Dave', 'Napur', 'Heedy', 'Shriva'];
            }
        </script> 
        <script src="https://code.angularjs.org/1.3.9/angular.js"></script> 
    </body>
</html>
1
  • 2
    there seems to be no controller or app defined in your HTML Commented Apr 30, 2016 at 20:00

4 Answers 4

2

First thing move angularjs cdn file reference before custom script to make angular object available before using it.

Thereafter do add ng-app="samples" on html element & ng-controller="SimpleController" on body tag will solve your issue. (Removed above line as OP modified his code after I answered).

Demo Here

Sign up to request clarification or add additional context in comments.

6 Comments

oh ! thanks , My mistake in my original code was First thing move angularjs cdn file reference before custom script to make angular object available before using it.
@Ashu you also need to add ng-app & ng-controller directive to make it working as I suggested in answer..did you looked at plunkr?
Can you please update this New Similar fiddle jsfiddle.net/7yejxcu3/9 ,this is not working, plz tell me reason too
Sure I'll look at it once I will have access to machine.. But ideally you could open new question, as you have already got answer for this question..
thanks it worked. I didn't ask new question because I feel it will scam this website by asking similar kind of multiple question.
|
0

You didn't declare the controller and so for the app. Edit as following : <div class="container" data-ng-controller="SimpleController" and <body data-ng-app="samples">

Comments

0

All you have to do is change the order in your file, no other operations necessary. See below:

<!DOCTYPE html>
<html>
  <head>
    <title>AngularJS Demos</title> 
    <script src="https://code.angularjs.org/1.3.9/angular.js"></script> 
  </head>
  <body> 
    <script  type="text/javascript">
      var samplesModule = angular.module('demoApp', []); 
      samplesModule.controller('SimpleController', SimpleController);
      function SimpleController($scope) {
        $scope.names = ['Dave', 'Napur', 'Heedy', 'Shriva'];
      }
    </script> 
    <div class="container" data-ng-app="demoApp" data-ng-controller="SimpleController">
      <h3>Adding a Simple Controller</h3>
      <ul>
        <li data-ng-repeat="name in names">{{name}}</li>
      </ul>
    </div> 
  </body>
</html>

Comments

0

You have not added ng-app and ng-controller to your View.

   <body > 
        <div ng-app="samples" class="container"  ng-controller="SimpleController">
            <h3>Looping with the ng-repeat Directive</h3>
            <h4>Data to loop through is initialized using ng-init</h4>
            <ul>
                <li data-ng-repeat="name in names">{{name}}</li>
            </ul>
        </div>
   </body>

Here is the working app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.