building modern web apps with angularjs

17
Building Modern Web Apps with ANGULARJS

Upload: raveen-perera

Post on 16-Jan-2017

43 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Building Modern Web Apps with AngularJS

Building Modern Web Apps with ANGULARJS

Page 2: Building Modern Web Apps with AngularJS

SPASingle Page Applications

Web application or website that fits on a single web page

Provides a more fluid user experience similar to a desktop application.

Either all necessary code (HTML, JS, and CSS) is retrieved with a single page load or dynamically loaded

Page 3: Building Modern Web Apps with AngularJS

Traditional vs SPA

Client Server

Initial request

Response(HTML+CSS+JS)

Form Post

Response(HTML+CSS+J

S)

Client Server

Initial request

Respond(HTML+CSS+JS)

AJAX

Response {JSON}

Page 4: Building Modern Web Apps with AngularJS

Techniques Frameworks➔ Ajax - Asynchronous JS and XML

➔ Websockets

➔ Server-sent events

➔ Browser plugins

➔ Angularjs

➔ Meteor.js

➔ Ember.js

Page 5: Building Modern Web Apps with AngularJS

What is AngularJS

AngularJS is a structural framework for dynamic web apps.

Page 6: Building Modern Web Apps with AngularJS

AngularJS DirectivesDirectives are Angular’s way of bringing additional functionality to HTML

➔ Ng-app

➔ ng-model

➔ ng-bind

➔ ng-click

➔ ng-controller

➔ ng-repeat

Page 7: Building Modern Web Apps with AngularJS

AngularJS ServicesIn AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application.

➔ $http

➔ $timeout

➔ $interval

Page 8: Building Modern Web Apps with AngularJS
Page 9: Building Modern Web Apps with AngularJS

Modules and Controllers

angular.module(‘moduleName’,[dependencies]);

angular.module('moduleName') .controller('controllerName', function () {

this.attributeName=”value”;

});

Page 10: Building Modern Web Apps with AngularJS

Expressions<body ng-app="moduleName">

....

<div ng-controller="controllerName">

<h1>{{attributeName}}</h1>

</div>

....

</body>

Page 11: Building Modern Web Apps with AngularJS

Expressions [example]<body ng-app="blogApp">

....

<div ng-controller="BlogCtrl as blog">

<h1>{{blog.title}}</h1>

</div>

....

</body>

Page 12: Building Modern Web Apps with AngularJS

Expressions [example 2]<body ng-app="blogApp">

....

<div ng-controller="BlogCtrl as blog">

<h1>{{blog.title}}</h1>

<input type="text" ng-model="blog.title" value="GDG"/>

</div>

</body>

Page 13: Building Modern Web Apps with AngularJS

Routesangular.config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl', controllerAs: 'main' }) .when('/about', { templateUrl: 'views/about.html', controller: 'AboutCtrl', controllerAs: 'about' }) .otherwise({ redirectTo: '/' }); });

Page 14: Building Modern Web Apps with AngularJS

Views and templates<body ng-app="blogApp">

....

<div class="container">

<div ng-view=""></div>

</div>

....

</body>

Page 15: Building Modern Web Apps with AngularJS

Directives ng-repeat<body ng-app="blogApp">

....

<div ng-controller="BlogCtrl as blog">

<h1 ng-repeat="posts as post">{{post.title}}</h1>

</div>

....

</body>

Page 16: Building Modern Web Apps with AngularJS

Servicesangular.module('moduleName') .service('serviceName', function() {

this.functionName=function(text){

return "Hello";

};

});

Page 17: Building Modern Web Apps with AngularJS

Services [Example]angular.module('blog') .service('postService', function() {

this.getPosts=function(){

return(Json);

};

});