I am a AngularJS beginner and I am using Angular 1.3.15 and I am facing the below error when I try to execute a simple script
Uncaught Error: [$injector:modulerr]
Html
<title>AngularJS data binding</title>
<script src="node_modules/angular/angular.min.js"></script>
<script src="myscript.js"></script>
<div data-ng-controller="SimpleController">
Name :
<br/>
<input type="text" ng-model="name"/>{{name |uppercase}}
<div>
<ul>
<li ng-repeat="personName in names">{{personName}}</li>
</ul>
</div>
</div>
JS file -
(function(){
var app = angular.module('myApp',[]);
app.controller('SimpleController', function($scope) {
$scope.names = ['test1','test2'];
});
})();
Does the code in the file myscript.js has to be in the (function()}) ?
Thanks,
(function () {})()is an Immediately Invoked Function. This means that any variables declared inside will be scoped to just that execution rather than the entire javascript environment.