ng-init

34
Ng-init Software Engeneering @ ISSATSo Member @ ISSATSo Google Club JSA @ JCertif TN @Hmidi Hamdi

Upload: hamdi-hmidi

Post on 17-Jul-2015

52 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Ng-init

Ng-init

Software Engeneering @ ISSATSoMember @ ISSATSo Google ClubJSA @ JCertif TN

@Hmidi Hamdi

Page 2: Ng-init

Must Know

HTML & CSSJavaScript Basics JSON NotationJS Functions REST API

Page 3: Ng-init

Downloading the Libraries

Download AngularJS http://angularjs.org/We’ll need angular.min.jsDownload Twitter Bootstrap http://getbootstrap.com/We’ll need bootstrap.min.css

Page 4: Ng-init

Agenda

1-Why Angular JS.2- What is Angular JS.3- Directives, Filters and DataBinding.4-Modules , Controllers and Scope.5- Dependecies and Services.6- Routing.

Page 5: Ng-init

Why Angular JS ?

Page 6: Ng-init

If you’re using JavaScript to create a dynamic webApps,Angular is a good choice.

• Angular helps you organize your JavaScript• Angular helps create responsive (as in fast) websites.• Angular is easy to test

• Flexible filters

Why AngularJS ?

Page 7: Ng-init

WebServer Web Browser

URL Request to server

Response with webPages & Assets

User Clicks on link, new Request

Response with webPages & Assets

Browser loads upentire webpage.

Browser loads upentire webpage.

Traditional Page-Refresh :

Page 8: Ng-init

WebServer

URL Request to server

Response with webPages & Assets

User Clicks on link, new Request

Response with JSON Data

Browser loads upentire webpage.

Data is loaded intoexisting page.

Responsive Website using Angular :

Web Browser

Page 9: Ng-init

What is AngularJS ?

Page 10: Ng-init

• A client-side JavaScript Framework for adding interactivity to HTML.• Open Source <3. • Devlopped By Google :p .• Used to build SPA Applications.• Based on the MVC pattern.

So ! What is Angular ?

Page 11: Ng-init

<!doctype html><html><head ng-app >

<title>Exemple 1</title><SCRIPT TYPE="text/javascript" src="JS/angular.min.js"></SCRIPT>

</head><body ><input type="text" ng-model="name" ><h1>Hello {{name}} </h1></body></html>

Hello User ?

Page 12: Ng-init

2 way DataBinding

Page 13: Ng-init

Directives, Filters and DataBinding

Page 14: Ng-init

A Directive is a way to teach HTML new Tricks.

Directives

Page 15: Ng-init

<!doctype html><html><head ng-app >

<title>Exemple 1</title><SCRIPT TYPE="text/javascript" src="JS/angular.min.js"></SCRIPT>

</head><body ><input type="text" ng-model="name" ><h1>Hello {{name}} </h1></body></html>

Example :

Page 16: Ng-init
Page 17: Ng-init

Modules , Controllers and Scope.

Page 18: Ng-init

• Where we write pieces of our Angular application.• Makes our code more maintainable, testable, and readable.• Where we define dependencies for our app.

Modules

Page 19: Ng-init

var app = angular.module('store', [ ] );

The Angular Core Module

Our AppName DependenciesModules that our appDepends on

<html ng-app=‘’store’’>

Our First Module

Page 20: Ng-init

• Controllers are where we define our app’s behavior by defining functions and values.

Controllers

Page 21: Ng-init

var app = angular.module('store', [ ]);//Our First Controllerapp.controller('StoreController', function($scope){

});

<div ng-controller="StoreController"><!-- HTML Tags Here --></div>

Our First Controller :

Page 22: Ng-init
Page 23: Ng-init

Dependecies and Services.

Page 24: Ng-init

Services give your Controller additional functionality, like ...

• Fetching JSON data from a web service with $http

• Logging messages to the JavaScript console with $log

• Filtering an array with $filter

Services :

Page 25: Ng-init

The $http Service is how we make an async request to a server ...• By using $http as a function with an options object:$http({ method: 'GET', url: '/products.json' });• Or using one of the shortcut methods:$http.get('/products.json', { apiKey: 'myApiKey' });• Both return a Promise object with .success() and .error()• If we tell $http to fetch JSON, the result will be automatically decoded into JavaScript objects and arrays.

Introducing $http Service :

Page 26: Ng-init

App.controller(‘MyContr’,function($scope,$http){$http.get('/products.json').success(function(data){//data contains the result });});

Example :

Page 27: Ng-init

Var app=angular.module(‘ClientMod’,[]);

app.factory(‘GetClients’,function($http){

return

{getClientById: function(id){

Return $http.get(‘getCl.php?id=’+id);

};

}

});

Var app=angular.module(‘Main’,[‘ClientMod’]);

app.Controller(‘Main’,

function($scope,GetClients){GetClients.getClientById(5)

.success(function(data){

$scope.Clients=data;

});

});

Dependencies:

Page 28: Ng-init
Page 29: Ng-init

Routing

Page 30: Ng-init

• The ngRoute module provides routing and deeplinking services and directives for angular apps.

NgRoute

Page 31: Ng-init

https://igctodoapi.herokuapp.com

Our API

Route HTTP Verb Detail

/GetTodos GET Get All Todos

/GetTodo/:id GET Get Todo By ID

/DeleteTodo/:id DELETE Delete Todo By ID

/AddTodo POST Add New Todo

Page 32: Ng-init
Page 33: Ng-init

CodeSchool : Shaping up with AngularJS

EggHead.Io : https://egghead.io

w3School : http://www.w3schools.com/angular/

More Tutorials

Page 34: Ng-init

<Thank You!>[email protected]

/+ HamdiHmidiigcien

/hamdi.igc