AngularJS basics презентация

Содержание

Слайд 2

Agile practitioner Trainer Public speaker Extensive AngularJS user

Agile practitioner
Trainer
Public speaker
Extensive AngularJS user

Слайд 3

Agenda Intro View and controller Directives and filters Two-way data

Agenda

Intro
View and controller
Directives and filters
Two-way data binding
Event handlers
RESTful services and $resource
Yeoman
Routing

Слайд 4

Intro Framework overview. Main concepts. Bootstrapping.

Intro

Framework overview. Main concepts. Bootstrapping.

Слайд 5

MVC IoC container Plain JS models All-in-One Modular design Testing bundled Directives

MVC

IoC container

Plain JS models

All-in-One

Modular design

Testing bundled

Directives

Слайд 6

MVC First introduced in 1979 by Trygve Reenskaug. Splits the

MVC

First introduced in 1979 by Trygve Reenskaug.
Splits the presentation from the

logic and the user input.

Controller

View

Model

Слайд 7

Inversion of Control Service Dependency Service Injector Dependency

Inversion of Control

Service

Dependency

Service

Injector

Dependency

Слайд 8

Bootstrapping TEMPLATE … … CODE angular.module('myApp', []);

Bootstrapping

TEMPLATE












CODE

angular.module('myApp', []);

Слайд 9

View and controller Controllers. Templates. Scopes.

View and controller

Controllers. Templates. Scopes.

Слайд 10

Angular view … {{phone.name}} {{phone.snippet}}

Angular view






{{phone.name}}

{{phone.snippet}}






Слайд 11

Controller View Model Scope Scope – the glue between model, view, and controller.

Controller

View

Model

Scope

Scope – the glue between model, view, and controller.

Слайд 12

Angular controller TEMPLATE {{data}} CODE angular.module('myApp') .controller('MyController', function($scope) { $scope.data = {}; });

Angular controller

TEMPLATE


{{data}}

CODE

angular.module('myApp')
.controller('MyController',
function($scope) {
$scope.data = {};
});

Слайд 13

Directives and filters Directives. ngRepeat. Filters.

Directives and filters

Directives. ngRepeat. Filters.

Слайд 14

Look and feel created {{event.child.id}} by forking this plunk .

Look and feel




user="event.user">
created
{{event.child.id}}

by forking this plunk .


Слайд 15

Forms of directives Preferred Element: Argument: also Class: Comment:

Forms of directives

Preferred
Element:
Argument:
also
Class:
Comment:

Слайд 16

ngRepeat [{{$index + 1}}] {{friend.name}} who is {{friend.age}}.

ngRepeat



  • [{{$index + 1}}] {{friend.name}} who

is {{friend.age}}.


Слайд 17

Filter [{{$index + 1}}] {{friend.name}} who is {{friend.age}}.

Filter



  • [{{$index +

1}}] {{friend.name}} who is {{friend.age}}.


Слайд 18

Standard filters currency date filter json limitTo uppercase number orderBy lowercase

Standard filters

currency
date
filter
json
limitTo

uppercase
number
orderBy
lowercase

Слайд 19

Practice #1

Practice

#1

Слайд 20

Task – goo.gl/grrTPW Create an angular application (bootstrap with ng-app).

Task – goo.gl/grrTPW

Create an angular application (bootstrap with ng-app).
Create a controller

and a template.
Initialize the list of repos in the controller.
Display the data on the view as a list of panels where the following is displayed:
Repo’s full name that is a link to the repo,
Repo owner’s login ID and avatar,
Repo’s description.
Output only 10 repos that come first alphabetically, order by full name ascending.
Слайд 21

Two-way data binding ngModel

Two-way data binding

ngModel

Слайд 22

ngModel

ngModel


Слайд 23

Practice #2

Practice

#2

Слайд 24

Task – goo.gl/CoqXPy Update the application so that the filtering

Task – goo.gl/CoqXPy

Update the application so that the filtering params can

be set on the page via inputs.
Default values should populate the inputs on load:
Filter: empty,
Sort by name: asc,
Limit: 10.
Each time any of the values changes, the displayed list updates accordingly.
Слайд 25

Event handlers Calling events from the view

Event handlers

Calling events from the view

Слайд 26

Event handlers TEMPLATE CODE angular.module('myApp') .controller('MyController', function($scope) { $scope.do = function() { }; });

Event handlers

TEMPLATE




CODE

angular.module('myApp')
.controller('MyController',
function($scope) {
$scope.do =

function() { };
});
Слайд 27

RESTful services and $resource HTTP and RESTful services. Injecting services.

RESTful services and $resource

HTTP and RESTful services. Injecting services.

Слайд 28

REST level HTTP level Client Server $resource (ngResource) RESTful resource $http XHR HTTP server

REST level

HTTP level

Client

Server

$resource
(ngResource)

RESTful resource

$http

XHR

HTTP server

Слайд 29

angular.module('myApp') .service('myService', function($resource) { ... }) .controller('MyController', function($scope, myService) { ... }); Injecting services ngRoute

angular.module('myApp')
.service('myService', function($resource) {
...
})
.controller('MyController', function($scope, myService) {
...
});

Injecting

services

ngRoute

Слайд 30

Practice #3

Practice

#3

Слайд 31

Task – goo.gl/75hgJq Update the application so that it gets

Task – goo.gl/75hgJq

Update the application so that it gets the list

of repos via the Github search API.
Add a panel with the search param that will allow to narrow the search request by:
Maximum repo size,
Minimum number of forks,
Minimum number of stars.
Add the “Search” button that will query the data based on the specified parameters.
Create a separate service named “Repository” for this and inject in the controller.
Using $resource get the following related data and add to each repo view:
Languages,
Contributors names and avatars.
Слайд 32

Yeoman Yeoman tool. Scaffolding. yo.

Yeoman

Yeoman tool. Scaffolding. yo.

Слайд 33

Yeomen Warders aka Beefeaters

Yeomen Warders

aka Beefeaters

Слайд 34

yo Scaffolding Grunt Task runner Bower Dependency management

yo
Scaffolding

Grunt
Task runner

Bower
Dependency
management

Слайд 35

Scaffolding is a technique, in which a specification is used to generate source code.

Scaffolding is a technique, in which a specification is used to

generate source code.
Слайд 36

Scaffolding tools examples

Scaffolding tools examples

Слайд 37

yo npm install –g yo generator-angular

yo

npm install –g yo generator-angular

Слайд 38

yo angular AngularJS generators

yo angular

AngularJS generators

Слайд 39

Angular generators angular:route angular (aka angular:app) angular:controller (service, directive, …)

Angular generators

angular:route

angular
(aka angular:app)

angular:controller (service, directive, …)

Слайд 40

Your app LiveReload Minification (HTML, CSS, JS, ngmin, …)

Your app

LiveReload

Minification
(HTML, CSS,
JS, ngmin, …)

Слайд 41

Practice #4

Practice

#4

Слайд 42

Task – goo.gl/yOC4Vx Create an application using yo AngularJS generator.

Task – goo.gl/yOC4Vx

Create an application using yo AngularJS generator.
Migrate the existing

code into this application using route and service generators. Use existing MainCtrl and main.html for your code.
Make sure the application runs on the Node JS server with the generated config.
Слайд 43

Configuring services Providers. Application phases.

Configuring services

Providers. Application phases.

Слайд 44

Providers are used for services configuration.

Providers are used for services configuration.

Слайд 45

Config Run Two execution phases

Config

Run

Two execution phases

Слайд 46

Example of a provider usage angular.module('myApp', []) .config(function($filterProvider) { $filterProvider.register('myFilter', MyFilter); });

Example of a provider usage

angular.module('myApp', [])
.config(function($filterProvider) {
$filterProvider.register('myFilter', MyFilter);
});

Слайд 47

Routing Multiple views. $routeProvider. $routeParams.

Routing

Multiple views. $routeProvider. $routeParams.

Слайд 48

partials/phone-list.html /phones $route (ngRoute) … … Page

partials/phone-list.html

/phones

$route
(ngRoute)







Page

Слайд 49

$routeProvider $routeProvider .when('/phones', { templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl' }) .otherwise({ redirectTo: '/phones' });

$routeProvider

$routeProvider
.when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
})
.otherwise({
redirectTo: '/phones'

});
Слайд 50

$routeParams // Given: // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby // Route: /Chapter/:chapterId/Section/:sectionId //

$routeParams

// Given:
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
// Route: /Chapter/:chapterId/Section/:sectionId
// Then
$routeParams ==> { chapterId: 1,

sectionId: 2, search: 'moby' }
Слайд 51

Practice #5

Practice

#5

Слайд 52

Task – goo.gl/nriURP Next to each repo entry in the

Task – goo.gl/nriURP

Next to each repo entry in the list add

the “Details” link.
Clicking on “Details” will navigate to the repo’s details page using AngularJS routing.
The page should contain the following information:
The same data that is shown for the repo in the repos list, plus
The list of contributors logins.
The page should also contain the “Back” link which will navigate back to the list of repos.
Try not to use yo angular:route.
Слайд 53

http://kirbarn.blogpost.com kiryl.baranoshnik@gmail.com @kirbarn

http://kirbarn.blogpost.com kiryl.baranoshnik@gmail.com @kirbarn

Имя файла: AngularJS-basics.pptx
Количество просмотров: 205
Количество скачиваний: 0