1

i'm new to angular, so started with very basic example, but this is also not working. so please help me out. below code should write the content of textbox to the page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head ng-app>
    <title></title>
</head>
<body>
    <div class="container">
        Name: <input type="text" ng-model="name" />{{name}}
    </div>
    <script src="/script/angular.js" type="text/javascript"></script>
</body>
</html>

5 Answers 5

1

ng-app should be inside html or body, inside whichever tags you intend to use angular.

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

1 Comment

you can include angular.js toward the bottom of page or in the header section, both works
1

In your code ng-app scope is ending with in head tags only. You haven't used ng-app at root level. You can use it at html or body or main div tag level. And there is no ng-controller in your markup. Of course you can also configure controller through js file also. You use below code.

HTML

<html ng-app="plunker">

<head>
  <script data-require="[email protected]" src="https://code.angularjs.org/1.3.14/angular.js" data-semver="1.3.14">    </script>
  <script src="app.js"></script>
</head>

<body ng-controller="MainCtrl">
  <div class="container">
      Name: <input type="text" ng-model="name" />{{name}}
  </div>
</body>

</html>

JS

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
});

5 Comments

Rajeshwar, for this simple example you don't have to create a controller. it started working by just placing the ng-app in html tag.
It is required, if you want to pre define your name variable. Other wise, i understand its not required.
does it means, i can use "World" instead of name?
If you don't use a controller, then text box will not be populated with any value. what ever u enter in the text box will be shown in place of {{name}}. But if you want to pre-populate the text box with some value you can define a controller and define variable name and u can assign some value. The the text box will be populated with the value u assigned to name variable in the controller.
thanks Rajeshwar! i implemented the same via controller. thanks for the info.
0

ng-app should be in html tag, not head.

Comments

0

put ng-app in tag, not in head tag

Comments

0

Remove ng-app directives which is added to head tag and assign it to html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.