1. First let's wrap the module in an anonymous function. The source code for the app.js file should look like the following
(function(){
'use strict';
var app = angular.module('shoppingList',['shoppingController']);
}());
The code above wraps the application in anonymous function and assigned to the variable call "app"
2. Now open the "shoppingController.js" in the "controllers" folder and wrap the "shoppingController" in anonymous function, the source code for the file should look like the following
(function(){
'use strict';
angular.module('shoppingController',[])
.controller('shoppingController',["$scope",function($scope){
$scope.shoppingListName="My Shopping List";
}]);
})());
3. Open up the "index.html" file and make sure the source code looks like the following.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Shopping List App</title>
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body ng-app="shoppingList" ng-controller="shoppingController">
{{shoppingListName}}
<script type="text/javascript" src="js/lib/angular/angular.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/controllers/shoppingController.js"></script>
</body>
</html>
4. In the command line where the root folder is type in "npm start"
5. Type int the following URL in your browser http://localhost:8000/ and you will see the following
Note: In order to see the application in your browser you must first run the "npm start" in your angular-seed folder first
In this tutorial we've taken some steps to future proof our application so that we are not working in the global environment
Posts In The AngularJS SPA Application Series:
No comments:
Post a Comment