I'm currently learning AngularJS, but I'm a little confused. This is the very very basic exercise about assigning a controller to a view vía ng-controller
. My web app consis of two files (index.html and js.js):
index.html:
<html>
<head>
</head>
<body ng-app="simpleApp">
<h1>Welcome to my website!</h1>
<div ng-controller="mainController">
<h2>This is my personal website :)</h2>
</div>
<script src="lib/angular.js"></script>
<script src="js.js"></script>
</body>
</html>
js.js:
var myApp = angular.module("simpleApp", []);
myApp.controller("mainController", function() {
console.log("It controller really works!!");
});
In most of the angular examples that I see, the global scope variable for the angular module has both the same name. But I use different (myApp
for the variable and simpleApp
for the name of the module) I'm a little weird about the code because I assign the mainController
, it's AngularJS detecting it via myApp variable or via simpleApp module? Why it doesn't work if ng-app=myApp
?.
Thanks.
Aucun commentaire:
Enregistrer un commentaire