[angularjs] from angular to mobile in 30 minutes

35
ANGULARJS DEC 2013

Upload: globant

Post on 02-Dec-2014

352 views

Category:

Technology


0 download

DESCRIPTION

By Gerónimo García (Software Designer Mobile Studio @Globant)

TRANSCRIPT

Page 1: [AngularJS] From Angular to Mobile in 30 minutes

ANGULARJS

DEC 2013

Page 2: [AngularJS] From Angular to Mobile in 30 minutes

¡Quiero ser un superhéroe!

Globant Proprietary | Confidential Information

Angularjs.org

“AngularJS is a toolset for building the framework most suited

to your application development. It is fully extensible and

works well with other libraries.”

Page 3: [AngularJS] From Angular to Mobile in 30 minutes

¡Quiero ser un superhéroe!

Globant Proprietary | Confidential Information

Page 4: [AngularJS] From Angular to Mobile in 30 minutes

¡Quiero ser un superhéroe!

Globant Proprietary | Confidential Information

Controller

Data Binding

POJO's

Deep linking

Form ValidationServer

Communication

Directives

Components

Localization

Embeddable

Injectable Testable

Page 5: [AngularJS] From Angular to Mobile in 30 minutes

Conocé tus superpoderes

Globant Proprietary | Confidential Information

$scope

Controllers

Views

Dependency Injection

Page 6: [AngularJS] From Angular to Mobile in 30 minutes

Conocé tus superpoderes

POJO's (Plain Old JavaScript Object)

Modelo

Conocé tus superpoderes | $scope

$scope

Globant Proprietary | Confidential Information

No se rige por UAP (Uniform Access Principle)

Flexible

Puente de comunicación

Nexo

$rootScope

Page 7: [AngularJS] From Angular to Mobile in 30 minutes

Conocé tus superpoderes

Permite definir el comportamiento detras del DOM

Comportamiento

Conocé tus superpoderes | Comtroller

Globant Proprietary | Confidential Information

Mantiene el orden de forma pristina y legible

Encapsulación

Robusto pero sin la necesidad de boilerplate

Expresividad

Controller

Page 8: [AngularJS] From Angular to Mobile in 30 minutes

Conocé tus superpoderes

Las vistas llevan HTML de lo más común

HTML

Conocé tus superpoderes | View

Globant Proprietary | Confidential Information

Potente motor de expresiones flexibls

Versatilidad

Agregar componentes especializados nunca fue más fácil

Extensible

View

Page 9: [AngularJS] From Angular to Mobile in 30 minutes

Conocé tus superpoderes

Simplicidad para seleccionar componentes

Simple

Conocé tus superpoderes | Dependency Injection

Globant Proprietary | Confidential Information

Todo se puede transformar en una depedencia inyectable

Modularizable

No más metodos main() que resultan ser tu peor pesadilla

Mantenible

DependencyInjection

Page 10: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

“Lo esencial es invisible a los ojos.”«Le pettit prince», Antoine de Saint-Exupéry

Page 11: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<!doctype html><html ng-app> <head> <script src="js/angularjs-1.2.0.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="todo.css"> </head> <body> <!-- We have some hidden awesomeness here --> </body></html>

Page 12: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<!doctype html><html ng-app> <head> <script src="js/angularjs-1.2.0.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="todo.css"> </head> <body> <!-- We have some hidden awesomeness here --> </body></html>

Page 13: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 14: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 15: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 16: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 17: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 18: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

<body> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body>

Page 19: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 20: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 21: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 22: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 23: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 24: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 25: [AngularJS] From Angular to Mobile in 30 minutes

Tomando el control

Globant Proprietary | Confidential Information

angular.module('todos').controller('TodoCtrl', ['$scope', function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; $scope.archive = function() { //More code };}]);

Page 26: [AngularJS] From Angular to Mobile in 30 minutes

¡Aguzando la vista!

Globant Proprietary | Confidential Information

Filters Routes

Services Directives

Page 27: [AngularJS] From Angular to Mobile in 30 minutes

¡Aguzando la vista!

Globant Proprietary | Confidential Information

Filters Dan formato a una expresión

Funcionan en controllers, views y services

Se pueden crear filtros custom

Ejemplos: currency date lowercase uppercase

Page 28: [AngularJS] From Angular to Mobile in 30 minutes

¡Aguzando la vista!

Globant Proprietary | Confidential Information

Services Son singletons

Deben cumplir una tarea especifica

Sirven como medio de comunicación entre controllers

Ejemplos: $http $location $animation

Page 29: [AngularJS] From Angular to Mobile in 30 minutes

¡Aguzando la vista!

Globant Proprietary | Confidential Information

Es un servicio (ngRoute)

Enlaza views, controllers y urls

Maneja pasaje de parametros

Adicionalmente, ganamos deep-linking!

Ejemplos: $routeProvider.when('/Book/:bookId/ch/:chapterId', { templateUrl: 'chapter.html', controller: ChapterCntl });

Routes

Page 30: [AngularJS] From Angular to Mobile in 30 minutes

¡Aguzando la vista!

Globant Proprietary | Confidential Information

Directives Son marcadores especiales dentro del DOM

Pueden adoptar la forma de attributes, elements, css

Menejan el HTML compiler de AngularJS

Ejemplos: <pane> ng-click ng-switch ng-repeat

Page 31: [AngularJS] From Angular to Mobile in 30 minutes

Una prueba de valor

Globant Proprietary | Confidential Information

Utiliza Karma Runner

Podemos usar cualquier testing framework (jasmine, chai, mocha)

Facilita inyectar dependencias y mock services

Unit tests y Tests End-to-End (E2E)

Page 32: [AngularJS] From Angular to Mobile in 30 minutes

Unit Tests Tests End-to-End (E2E)

Una prueba de valor

Globant Proprietary | Confidential Information

function PasswordCtrl($scope) { $scope.password = ''; $scope.grade = function() { var size = $scope.password.length; if (size > 8) { $scope.strength = 'strong'; } else if (size > 3) { $scope.strength = 'medium'; } else { $scope.strength = 'weak'; } };}

var $scope = {};var pc = $controller('PasswordCtrl', { $scope: $scope });

$scope.password = 'abc';$scope.grade();expect($scope.strength).toEqual('weak');

describe('Buzz Client', function() { it('should filter results', function() { input('user').enter('jacksparrow'); element(':button').click(); expect(repeater('ul li').count()).toEqual(10); input('filterText').enter('Bees'); expect(repeater('ul li').count()).toEqual(1); });});

Page 33: [AngularJS] From Angular to Mobile in 30 minutes

¡Al infinito y más allá!

Globant Proprietary | Confidential Information

Validation framework

AJAX support ($http & $resource)

Otros servicios ($apply, $digest, $watch y $q)

Page 34: [AngularJS] From Angular to Mobile in 30 minutes

Q&A

Page 35: [AngularJS] From Angular to Mobile in 30 minutes

Thank You

By yours truly

Thank You

@geronimogarcia

DarkThrone

[email protected]