34
AngularJS is awesome! Eusebiu Schipor - Frontend Developer

AngularJS is awesome

Embed Size (px)

Citation preview

Page 1: AngularJS is awesome

AngularJS is awesome!

Eusebiu Schipor - Frontend Developer

Page 2: AngularJS is awesome
Page 3: AngularJS is awesome

http://angularjs.org

Page 4: AngularJS is awesome

AngularJS:

• Is a client-side MVW JavaScript framework for writing single page web applications.• It's built and mantained by Google.• Help us building testable web applications that scale.• It lets you use HTML as your template language and lets

you extend HTML's syntax to express your application's components clearly and succinctly.• The unique and innovative features are two-way-data

bindings, dependency injection, easy-to-test code and extending the HTML dialect by using directives.

Page 5: AngularJS is awesome

Some key features of the Angular JS in web development:

• Two way data binding• MVC framework• Templating• Custom-directive (reusable components)• REST-friendly• Set up a link for any dynamic page• Form Validation• Server Comunication• Localization• Dependency injection• Full testing environment• AngularJS can do everything that jQuery does and much more, yet is roughly

equivalent in download size

Page 6: AngularJS is awesome

AngularJS vs jQueryjQuery AngularJS

Restful API NO YES

Integration test runner NO YES

MVC support NO YES

Template NO YES

Two way data binding NO YES

Dependency injection NO YES

AJAX YES YES

Cross Module Communication YES YES

Unit test runner YES YES

Form validation NO YES

Localization NO YES

File size 32 kb 38 kb

Page 7: AngularJS is awesome

Model-View-Controller Architecture

Page 8: AngularJS is awesome
Page 9: AngularJS is awesome

Single Page Applications (SPA)• In a Single Page Application (SPA), either all necessary code (HTML, CSS,

JavaScript) is retrieved with a single page load.• Appropiate resources are dynamically loaded and added to the page as

necessary, ussually in response to user actions.• The page does not reload at any point in the process.• Interaction with the single page application often involves dynamic

communication with the web server behind the scenes.• SPAs are backe-end independent, and we only care about the JSON

data coming back, be it from JAVA, .NET, PHP or any other server-side language.

Page 10: AngularJS is awesome

Main components of AngularJS:

• Directives - HTML annotations that trigger JavaScript behaviors• Modules - Where our application components live• Controllers - Where we add application behavior• Expressions - How values get displayed within the page

Page 11: AngularJS is awesome
Page 12: AngularJS is awesome

Getting started

Page 13: AngularJS is awesome

Modules

• We can think of a module as a container for the different parts of your app – controllers, services, filters, directives, etc.• A container for different parts of application• Modules can have other modules as dependencies

Page 14: AngularJS is awesome

Creating a module

Page 15: AngularJS is awesome

Controllers

• An Angular Controller allows us to interact with a View and Model, it's the place where presentational logic can take place to keep the UI bindings in sync with the Model.

Page 16: AngularJS is awesome

Dependency injection

When MyController is created by AngularJS, the $scope and instances of dep1 and dep2 are automatically passed in. This eliminates the need for hard-coding dependencies with global variables or creating instances manually within the component, which greatly complicates and limits testability.

Page 17: AngularJS is awesome

Expressions

• Allow you to insert dynamic values into your HTML.• AngularJS expressions are written inside double braces: {{expression}}• Binds data to HTML the same way as the ng-bind directive, and

output the data exactly were the directive is written.• They are used for small calculations only or getting the value of

$scope properties.

Page 18: AngularJS is awesome

$scope

• Every controller has an associated $scope object.• $scope is an object that refers to the application model• In the Model-View-Controller structure, the $scope

object becomes the model.• We only use $scope inside Controllers, where we bind

data from the Controller to the View.

Page 19: AngularJS is awesome

Views

Page 20: AngularJS is awesome

DirectivesAngularJS extends HTML through use of directives, a feature that allows you to create your own HTML elements.- ng-app directive initializes an AngularJS application.- ng-init directive initializes application data.- ng-click directive allows you to specify custom behavior when an element is clicked

Page 21: AngularJS is awesome

Using directives

_

Page 22: AngularJS is awesome

Custom Directives

Page 23: AngularJS is awesome

Using filters• A filter formats the value of an expression for display to

the user. They can be used in view templates, controllers or services and it is easy to define your own filter.

Page 24: AngularJS is awesome

Two-way Data Binding

• Data-binding is an automatic way of updating the view whenever the model changes, as well as updating the model whenever the view changes.

Page 25: AngularJS is awesome

AngularJS form validation• There are many form validation directives available in AngularJS:

Page 26: AngularJS is awesome

Creating templates

Page 27: AngularJS is awesome

$http Service

The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

Page 28: AngularJS is awesome

Custom services

• We can define our own custom services in AngularJS apps and use them wherever required.• There are several ways to declare AngularJS service

within application. Following are two simple ways:

Page 29: AngularJS is awesome

The Role of Factories

Page 30: AngularJS is awesome

AngularJS routing• Since we are making a single page application and we

don’t want any page refreshes, we’ll use Angular’s routing capabilities.

Page 31: AngularJS is awesome

Defining routes

Page 32: AngularJS is awesome

Pain Points

• Angular Expressions are used extensively in the View layer of Angular.• It lets the developer use complicated logic and even

perform assignment operations and calculations, all inside the view templates• Putting logic inside the templates makes it harder to

test, sometimes impossible to test.

Page 33: AngularJS is awesome

Summary• AngularJS provides a robust “SPA” framework for bulding robust

client-side applications.

Key features:• Directives and filters• Two-way data binding• Views, Controllers, Scope• Modules and Routes

Page 34: AngularJS is awesome

Resources• http://angularjs.org• http://builtwith.angularjs.org• http://angular-ui.github.io• http://mgcrea.github.io/angular-strap• http://pluralsight.com