Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularJS ng-app value issue

The following code works.

<body ng-app="" ng-init="names=['a','b']">
    <ul ng-repeat="x in names">
        <li >
             {{ x }}
        </li>
    </ul> 
</body>

but as soon I add a value to ng-app (say ng-app="myApp"), it stops working. Anyone would know why?

like image 378
Nick P Avatar asked May 03 '26 18:05

Nick P


1 Answers

Because, you told angular by specifying name, that in this page all objects definitions and details which I am going to use is defined in a module called my app. Angular Search for it and does not find.

when you specify the ng-app you should specify the app definition, controller you can initialize these values from ng-init.

<html>
<body>
<div ng-app="myapp" controller="MyController">
      <span>{{personname}}</span>
</div>

<script>
// this will setup the myapp
var app = angular.module('myapp', []);
app.controller('MyController',function(){
$scope.personname='tammi';
});
</script>

</body>
</html>
like image 104
Faheem Ahmad Avatar answered May 05 '26 09:05

Faheem Ahmad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!