by Zachariah Moreno
By Google
M => Model => Data
V => View => Pages
C => Controller => Logic
separation of concerns
A standard way to organize a complex codebase
ng-coastal/
--- index.html
--- coastal.js
--- coastal.css
--- pages/
------ home/
--------- home.html
--------- home.js
--- images/
------ all images
--- components/
------ angularjs/
------ all 3rd-party additions
that's where Routes come in
So our file/folder structure is not tied to our URLs...
‹html ng-app="coastal"›
‹head›
‹/head›
‹body›
‹/body›
‹/html›
Textbook stuff
angular.module('coastal', [
// global dependencies
'ngRoute',
// pages
'coastal.home',
...
])
// redirect to /home if attempted route does not exist
.config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/home'});
}]);
Global/application module that ties most everything together
We only need touch this file if we add a new page or module
angular.module('coastal.home', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/home', {
templateUrl: 'pages/home/home.html',
controller: 'HomeCtrl'
});
}])
.controller('HomeCtrl', [function() {
...
}]);
We only need touch this file if we add logic to the home page/view
...
Nothing new here
We only need touch this file if add or update content to the home page/view
it's the same process as today, except easier to locate because our file/folder structure mirrors our navigation
Only steps 2, 4 & 5 are additions to our current process
.controller('HomeCtrl', ['$scope', 'Data', function($scope, Data) { ... }]);
$scope.data = Data;
{{ data }}
- {{ item }}
Hello {{ yourName }}
We've already extended Angular with modules for each page & for accessing our Data
Beyond that, Angular has a HUGE developer community that regularly Open Sources 3rd party modules
NG-Modules.org