Jan
30
2016
By abernal
We can split the application into diferent modules, for example we can create a new module called 'store-directives' that will store all the directives related to a specific part of the store
Example using product.js to store the module store-directives
Within the index.html, check the src="products.js"
<!DOCTYPE html> <html ng-app="gemStore"> <head> <link rel="stylesheet" type="text/css" href="bootstrap.min.css" /> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="app.js"></script> <script type="text/javascript" src="products.js"></script> </head>
Within the apps.js, check the ['store-directives'] within the module definition
(function() { var app = angular.module('gemStore', ['store-directives']); app.controller('StoreController', function(){ this.products = gems; }); ... } )();
Within the products.js
(function() { var app = angular.module('store-directives', []); app.directive("productDescription", function() { return { restrict: 'E', templateUrl: "product-description.html" }; }); app.directive("productReviews", function() { return { restrict: 'E', templateUrl: "product-reviews.html" }; }); app.directive("productSpecs", function() { return { restrict:"A", templateUrl: "product-specs.html" }; }); app.directive("productTabs", function() { return { restrict: "E", templateUrl: "product-tabs.html", controller: function() { this.tab = 1; this.isSet = function(checkTab) { return this.tab === checkTab; }; this.setTab = function(activeTab) { this.tab = activeTab; }; }, controllerAs: "tab" }; }); app.directive("productGallery", function() { return { restrict: "E", templateUrl: "product-gallery.html", controller: function() { this.current = 0; this.setCurrent = function(imageNumber){ this.current = imageNumber || 0; }; }, controllerAs: "gallery" }; }); })();