Slide 1

Slide 1 text

Google+: klab.ca/+ Twitter: @PearlChen ain’t just another MVC framework Pearl Chen [email protected] AngularJS

Slide 2

Slide 2 text

Me Technologist + Educator frontend web developer hardware hacker emerging technology & user experience (‘artist’) Ladies Learning Code instructor Teach Android & Arduino workshops former CFC Media Lab Research & Tech Manager Teach kids Scratch programming

Slide 3

Slide 3 text

Day job: Frontend Tech Lead Can you build responsive web sites? Come work with me -- TELUS is hiring!

Slide 4

Slide 4 text

The Superheroic JavaScript MVW Framework Beginner to intermediate? AngularJS is opinionated and will save you from the spaghetti code monster. More advanced? Create complex web apps in a simpler way. Write code with unit testing in mind. Model-View- Whatever ^

Slide 5

Slide 5 text

MVC refresher Model your application data (e.g. Values typed into a form field. Or the results of a database call.) Controller mediator between the model & view (e.g. When a form field is updated, it takes care of saving that data. Or when data comes back from an API call, tells the view to update.) View a representation of the model data (e.g. What the user sees on a webpage.)

Slide 6

Slide 6 text

MVC -- the Angular Way Model your application data (e.g. An array of values) Whatever mediator between the model & view (e.g. Passes data back and forth seamlessly* via data binding) View a representation of the model data (html fragment w/ ng-controller attribute)

Slide 7

Slide 7 text

Other MVC frameworks? Backbone.js (backbonejs.org) was one of the first and has huge traction due to its early beginnings. • Gives you a way to organize your code via an API after extending Backbone classes. • It is very un-opinionated. • It’s up to you to use it as much, or as little as you want to. “If the framework doesn’t write the code, YOU have to.” - Backbonejs vs Angularjs : Demystifying the myths

Slide 8

Slide 8 text

Angular is a MVC Framework but... There is nothing to inherit, nothing to call, and no complex life cycle for your controllers to follow. [...] It really is just a better browser.”- Misko Hevery

Slide 9

Slide 9 text

In contrast... Angular: • Is very opinionated. (e.g. There is typically a “right” way to do it.) • Gives you a way to organize your code but feels like you’re just writing HTML and JS, not extending classes. • Does a lot of heavy lifting for you (Mainly around DOM manipulation using data binding.)

Slide 10

Slide 10 text

Re-envision web development “Angular is what the web browser would have been, had it been designed for applications.” - Misko Hevery, Appliness (Feb #11): appliness.com

Slide 11

Slide 11 text

Remember document.getElementById()? var  hello  =  “Hey,  jQueryTO!”; Old school way to dynamically update text:
document.getElementBy(‘message’).textContent  =  hello; Then that got replaced by $(selector)...
  $(‘#message’).text(  hello  ); Now, with Angular!
{{hello}}

Slide 12

Slide 12 text

A simple AngularJS HTML file            
           Name:                        

Hello  {{yourName}}!

       
           

Slide 13

Slide 13 text

A slightly more complex AngularJS app    .highlight  {  /*  some  CSS  styles  */  }    
       
           {{tada}}!        
       Add  Highlight        Fade  Highlight    
       

Slide 14

Slide 14 text

Its matching application JavaScript file function  MagicCtrl($scope)  {    $scope.tada  =  “It’s  like  magic!”;    $scope.highlight  =  false;      $scope.glow  =  function()  {        $scope.highlight  =  true;    };    $scope.fade  =  function()  {        $scope.highlight  =  false;    }; }

Slide 15

Slide 15 text

Let’s see this in practice!

Slide 16

Slide 16 text

Being built on AngularJS... codehuddle.org And being built open source: github.com/CodeHuddle/

Slide 17

Slide 17 text

Use Yeoman to build your Angular apps Yeoman is an opinionated* way to quickly scaffold out the basic web files of a web application. *Although less opinionated for version 1.0

Slide 18

Slide 18 text

Warning!!! Examples based on Yeoman version 0.9.6. (Version 1.0 beta was released just last week.)

Slide 19

Slide 19 text

AngularJS has a Yeoman generator! • Packaged by default with Yeoman 0.9.6. • Found in your Yeoman generators directory. (/usr/local/lib/node_modules/yeoman/node_modules/yeoman-generators/lib/generators) • Or update/install it locally to your project folder: npm  install  generator-­‐angular Github project (github.com/yeoman/generator-angular) maintained by Brian Ford on the AngularJS team so follow him on Google+

Slide 20

Slide 20 text

Using the default generator... (1) Start with an empty folder*. *Generator will automatically use folder name to create a namespace for your app so don’t use numbers or non-letter characters ** demo ** yeoman  init  angular ( v1.0: yo  init  angular )

Slide 21

Slide 21 text

Other commands: route (1) Creates both a view (an html fragment) and a controller (a JS file) (2) Links to the controller file in index.html (3) Updates the $routeProvider in app.js. (4) Creates stubs for your unit tests in /tests ** demo ** yeoman  init  angular:route  name-­‐of-­‐your-­‐route

Slide 22

Slide 22 text

Other commands: directive (1) Creates a directive (a way to encapsulate DOM manipulation) (2) Links to the directive file in index.html ** demo ** yeoman  init  angular:directive  name-­‐of-­‐your-­‐directive Check out AngularUI (angular-ui.github.com) for more UI directives.

Slide 23

Slide 23 text

Other commands: filter (1) Creates a filter (logic to manipulate data so the view can use it) (2) Links to the filter file in index.html ** demo ** yeoman  init  angular:filter  name-­‐of-­‐your-­‐filter

Slide 24

Slide 24 text

Learning more about Angular • Official AngularJS website: angularjs.org • AngularJS Google+ Community: plus.google.com/communities/ 115368820700870330756 • Egghead.io video tutorials: egghead.io

Slide 25

Slide 25 text

Thank you! Upcoming workshops: MaKey MaKey for Game Makers: klab.ca/makeymakey Intro to Arduino + Breadboarding: klab.ca/events Reminder: TELUS is hiring! Come talk to me. Google+: klab.ca/+ Twitter: @PearlChen Pearl Chen [email protected]