SlideShare a Scribd company logo
1 of 60
Download to read offline
MODULAR ANGULARJS
WHO AM I?
@dhyegofernando
PLUGINS? I SEE EVERYWHERE
VANILLA JS PLUGINS
var plugin = new Plugin(document.querySelector('.plugin­selector'));
JQUERY PLUGINS
$('.plugin­selector').plugin();
ANGULARJS FTW
WHY ANGULARJS?
DATA-BINDING
DATA-BINDING JQUERY EXAMPLE
$('#input­name').on('change', function() { 
  $('#greeting­name').text(this.value); 
});
ONE WAY DATA-BINDING
TWO WAY DATA-BINDING
DATA-BINDING EXAMPLE
<div ng­app> 
  <label>Name:</label> 
  <input type="text" ng­model="yourName"> 
  <hr> 
  <h1>Hello {{yourName}}!</h1> 
</div>
DEPENDENCY INJECTION
DEPENDENCY INJECTION EXAMPLE
DEPENDENCY INJECTION EXAMPLE
<div ng­app="app" ng­controller="GreetingController"> 
  <form ng­submit="greet()"> 
    <input type="text" ng­model="name"> 
    <button type="submit">Greet</button> 
  </form> 
</div>
angular.module('app', []) 
  .controller('GreetingController', function($scope) { 
    $scope.name = 'John Doe'; 
    $scope.greet = function() { 
      alert('Hello ' + $scope.name); 
    }; 
  });
DIRECTIVES
TAB COMPONENT
NON-SEMANTIC TAB COMPONENT
<div id="tab"> 
  <ul class="tab­head"> 
    <li><a href="#content­1">Title 1</a></li>
    <li><a href="#content­2">Title 2</a></li>
    <li><a href="#content­3">Title 3</a></li>
  </ul> 
  <div id="content­1" class="tab­content"> 
    <p>Content 1 goes here</p> 
  </div> 
  <div id="content­2" class="tab­content"> 
    <p>Content 2 goes here</p> 
  </div> 
  <div id="content­3" class="tab­content"> 
    <p>Content 3 goes here</p> 
  </div> 
</div>
$('#tab').tab();
SEMANTIC TAB COMPONENT
<tabset> 
  <tab heading="Title 1"> 
    <p>Content 1 goes here</p> 
  </tab> 
  <tab heading="Title 2"> 
    <p>Content 2 goes here</p> 
  </tab> 
  <tab heading="Title 3"> 
    <p>Content 3 goes here</p> 
  </tab> 
</tabset>
NOW LET'S LET THE THINGS A LITTLE BIT MORE INTERESTING
TODO APP
FEATURES
Tasks
List
Add
Mark/Unmark as complete
Archive
TODO APP: THE WRONG WAY
STRUCTURE
|­­ js/ 
|   |­­ controllers.js 
|   |­­ directives.js 
|   |­­ services.js 
|   |­­ app.js 
|­­ index.html
index.html
... 
<div ng­controller="TodoController"> 
  <span>{{remaining()}} of {{tasks.length}} remaining</span> 
  [ <a href="" ng­click="archive()">archive</a> ] 
  <ul> 
    <li ng­repeat="task in tasks"> 
      <input type="checkbox" ng­model="task.done"> 
      <span class="done­{{task.done}}">{{task.text}}</span> 
    </li> 
  </ul> 
  <form ng­submit="addTask()"> 
    <input type="text" ng­model="taskText"> 
    <input type="submit" value="add"> 
  </form> 
</div> 
...
app.js
angular.module('app', ['app.controllers']);
controllers.js
angular.module('app.controllers') 
  .controller('TodoController', ['$scope', function($scope) { 
    $scope.tasks = []; 
    $scope.addTask = function() { // ... }; 
    $scope.remaining = function() { // ... }; 
    $scope.archive = function() { // ... }; 
  }]) 
  .controller('OtherController', ['$scope', function($scope) { 
    // ... 
  }]);
COMMON APPROACH MISTAKES
FILES STRUCTURE
NEVER
SEPARATE FILES IN FOLDER BY THEIR TYPE
|­­ js/ 
|   |­­ controllers.js 
|   |­­ directives.js 
|   |­­ services.js 
|   |­­ app.js 
|­­ index.html
ALWAYS
SEPARATE FILES IN THEIR COMPONENT NAME FOLDER
|­­ src/ 
|   |­­ todo/ 
|   |   |­­ todo.html 
|   |   |­­ todo.module.js 
|   |   |­­ todo.config.js 
|   |   |­­ todo.controller.js
|   |   |­­ todo.controller.spec.js 
|   |­­ tasks/ 
|   |   |­­ tasks.module.js 
|   |   |­­ tasks.service.js 
|   |   |­­ tasks.service.spec.js 
|   |   |­­ tasks.directive.js
|   |   |­­ tasks.directive.spec.js 
|   |­­ app.module.js 
|   |­­ index.html
MODULES (OR LACK THEREOF)
NEVER
SEPARATE MODULES BY THEIR TYPE
controllers.js
angular.module('app.controllers') 
  .controller('TodoController', ['$scope', function($scope) { 
    $scope.tasks = []; 
    $scope.addTask = function() { // ... }; 
    $scope.remaining = function() { // ... }; 
    $scope.archive = function() { // ... }; 
  }]) 
  .controller('OtherController', ['$scope', function($scope) { 
    // ... 
  }]);
ALWAYS
SEPARATE MODULES BY THEIR COMPONENT NAME
todo/todo.controller.js
angular.module('todo') 
  .controller('TodoController', ['$scope', function($scope) { 
    $scope.tasks = []; 
    $scope.addTask = function() { // ... }; 
    $scope.remaining = function() { // ... }; 
    $scope.archive = function() { // ... }; 
  }]);
app.module.js
angular.module('app', [
  'todo' 
]);
TOO MANY CONTROLLERS RESPONSIBILITY
NEVER
LET CONTROLLERS DO A LOT OF OTHERTHINGS
(LIKE PERSIST)
controllers.js
angular.module('app.controllers') 
  .controller('TodoController', ['$scope', function($scope) { 
    $scope.tasks = []; 
    $scope.addTask = function() { // ... }; 
    $scope.remaining = function() { // ... }; 
    $scope.archive = function() { // ... }; 
  }]) 
...
ALWAYS
LET CONTROLLERS AS CLEAN AS POSSIBLE
(AND ISOLATE SHARED BEHAVIOURS IN SERVICES)
todo/todo.controller.js
angular.module('todo') 
  .controller('TodoController', ['$scope', 'Tasks', function($scope) { 
    $scope.tasks = Tasks.get(); 
    $scope.addTask = function() { Tasks.add(); }; 
    $scope.remaining = function() { Tasks.count(); }; 
    $scope.archive = function() { Tasks.archive(); }; 
  }]);
tasks/tasks.service.js
angular.module('tasks')
  .factory('Tasks', ['$http', function($http) { 
    return { 
      get: function() { $http.get(); }, 
      add: function() { $http.post(); }, 
      count: function() { $http.get().length; }, 
      archive: function() { $http.put(); } 
    }; 
  }]);
JUST SOME TIPS TO KEEP THINGS BETTER...
SHARE BEHAVIOURS THROUGH COMPONENTS BUT
DO NOT REINVENT THE WHEEL
HOW TO LOOK FOR A COMPONENT
WHERE TO FIND COMPONENTS?
ANGULARJS DOCS
BOWER.IO
NGMODULES.ORG
HOW TO USE A COMPONENT?
Download or Install the component
bower install ­­save angular­material
Load the component files
<link href="angular­material.min.css" rel="stylesheet"> 
<script src="angular­material.min.js">
Set as a module dependency
angular.module('app', [
  'ngMaterial' 
]);
WHAT DO I HAVE TO DO TO BUILD MY OWN COMPONENT?
WRITE GREAT TESTS
WRITE SOME DOCUMENTATION
FOLLOW THE STYLE GUIDE
USE GENERATORS
AND FINALLY PUBLISH IT
bower init && bower publish
QUESTIONS?
NOW... IT'S UP TO YOU
THANK YOU
github.com/dhyegofernando
twitter.com/dhyegofernando
SLIDES
bit.ly/1F3KyH2

More Related Content

What's hot

Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
ciconf
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Masahiro Akita
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
Aaron Brazell
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 

What's hot (20)

Java script functions
Java script   functionsJava script   functions
Java script functions
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Barely Enough Design
Barely Enough DesignBarely Enough Design
Barely Enough Design
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
Dealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsDealing With Legacy PHP Applications
Dealing With Legacy PHP Applications
 
Automated testing for client-side - Adam Klein, 500 Tech
Automated testing for client-side - Adam Klein, 500 TechAutomated testing for client-side - Adam Klein, 500 Tech
Automated testing for client-side - Adam Klein, 500 Tech
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Let's write secure drupal code!
Let's write secure drupal code!Let's write secure drupal code!
Let's write secure drupal code!
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
 
Keeping It Simple
Keeping It SimpleKeeping It Simple
Keeping It Simple
 
Framework
FrameworkFramework
Framework
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
 
Oop php 5
Oop php 5Oop php 5
Oop php 5
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 

Similar to Modular Angular JS

Similar to Modular Angular JS (20)

Angular JS Introduction
Angular JS IntroductionAngular JS Introduction
Angular JS Introduction
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Angular js
Angular jsAngular js
Angular js
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
Built in filters
Built in filtersBuilt in filters
Built in filters
 
Jquery
JqueryJquery
Jquery
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Components
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference Client
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
AngularJs
AngularJsAngularJs
AngularJs
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 

Recently uploaded

Recently uploaded (20)

Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 

Modular Angular JS