Top Banner
Twitter @dgoutam Javascript for Designers
35

Angularjs for kolkata drupal meetup

May 07, 2015

Download

Technology

Goutam Dey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Angularjs for kolkata drupal meetup

Twitter @dgoutam

Javascript for Designers

Page 2: Angularjs for kolkata drupal meetup

History

• Origins within Google, invented by Misko Hevery

• Open-sourced 2009• 17,000 lines in 6 months => 1,500 in 3 weeks

Page 3: Angularjs for kolkata drupal meetup

Killer Features

• Two-way binding• Declarative coding for UI• Teaching HTML new tricks• Separation of model & view, No DOM/View

manipulation, less code• Great for CRUD based single page apps• Awesome adoption and great community• Unit testable, E2E testable

Page 4: Angularjs for kolkata drupal meetup

http://angularjs.org

Page 5: Angularjs for kolkata drupal meetup

ng-app, expression binding

Page 6: Angularjs for kolkata drupal meetup

ng-app, expression binding

• Include angular.js or angular.min.js• Add ng-app declarative where you want

Angular to manage app (typically <html> or <body>)

• Expression binding with {{ }}• ng-app can also be written as ngApp• Use camel case in JavaScript code (ngApp) and

use snake case in html (ng-app)

Page 7: Angularjs for kolkata drupal meetup

How does it work

• Compile: traverse the DOM and collect all of the directives. The result is a linking function.

• Link: combine the directives with a scope and produce a live view.

Page 8: Angularjs for kolkata drupal meetup

ngModel, binding variables

• 02-ngModel• ng-model binds variable data. It can be

declared on input, select, textarea, etc.

Page 9: Angularjs for kolkata drupal meetup

Two-way data binding

Page 10: Angularjs for kolkata drupal meetup

Jquery vs Angular

Page 11: Angularjs for kolkata drupal meetup

Differences from jQuery

• Declarative code, not imperative (explicitly stating, say with functions, what action needs to be performed)

• Automatic data binding• No direct DOM manipulation

Page 12: Angularjs for kolkata drupal meetup

More expressions

Page 13: Angularjs for kolkata drupal meetup

Expressions

• Expressions can be embedded anywhere• … even for class values• There are special filters that you can use

(currency)• Values are automatically bound

Page 14: Angularjs for kolkata drupal meetup

MVC

Page 15: Angularjs for kolkata drupal meetup

Scope and Controller

Page 16: Angularjs for kolkata drupal meetup

Learnings

• Controller objects can separate data and functionality– There can be many controllers

• ‘$scope’ is injected by AngularJS• $scope.data in the controller is referred to as

simply data in html• Dot notation for object members works

(person.age)– In fact, this is suggested practice

Page 17: Angularjs for kolkata drupal meetup

Scope, Controller, View

Page 18: Angularjs for kolkata drupal meetup

How AngularJS does MVC

Page 19: Angularjs for kolkata drupal meetup

Dependency Injection

Page 20: Angularjs for kolkata drupal meetup

Method on Scope

Page 21: Angularjs for kolkata drupal meetup

ngClick

Page 22: Angularjs for kolkata drupal meetup

ngRepeat

Page 23: Angularjs for kolkata drupal meetup

ngRepeat

Page 24: Angularjs for kolkata drupal meetup

Filters

Page 25: Angularjs for kolkata drupal meetup

Other inbuilt filters

Page 26: Angularjs for kolkata drupal meetup

Modules in AngularJS

• Third party code can be packaged as reusable modules.

• The modules can be loaded in any/parallel order (due to delayed nature of module execution).

• Some Angular modules are in separate files: Eg. ngRoute is in angularjs-route.min.js

Page 27: Angularjs for kolkata drupal meetup

ngView and Routing

Page 28: Angularjs for kolkata drupal meetup

$http

Page 29: Angularjs for kolkata drupal meetup

$http

• Make AJAX calls with $http• It returns deferred promises– More in later workshops

• You can handle ‘success’ and ‘error’

Page 30: Angularjs for kolkata drupal meetup

Working with angular-seed

• https://github.com/angular/angular-seed• You need to have node.js installed to test

Page 31: Angularjs for kolkata drupal meetup

Custom Filter

Page 32: Angularjs for kolkata drupal meetup

Custom Directive

Page 33: Angularjs for kolkata drupal meetup

What we didn’t cover

• Unit testing, E2E testing• Custom directives beyond basics• $apply and digest cycles• $q and promises• Service, Factory, Provider

Page 34: Angularjs for kolkata drupal meetup

Resources

• angularjs.org• Google Groups: AngularJS• Google+: AngularJS• ngmodules.org• Github: angular-ui.github.io• Google+: AngularJS India• https://www.facebook.com/groups/

255769184523171/

Page 35: Angularjs for kolkata drupal meetup