On Github ZachMoreno / ng-coastal-slides
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› <!-- meta --> <!-- css --> ‹/head› ‹body› <!-- navigation --> <div ng-view=""></div> <!-- js --> ‹/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
<any> <markup> <content> ... </content> </markup> </any>
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) { ... }]);Then we make the Data available to home.html in our home.js controller like this
$scope.data = Data;& in home.html we can inject the data like this
<h3>{{ data }}</h3>Moreover, we can repeat many items like this
<ol ng-repeate="item in data"> <li>{{ item }}</li> </ol>
<label>Name:</label> <input type="text" ng-model="yourName" placeholder="Enter a name here"> <hr> <h1>Hello {{ yourName }}</h1>
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