angular js architecture (v1.4.8)

17
Angular JS v1.4.8 TECH SESSION Lapusneanu Gabi Costel

Upload: gabi-costel-lapusneanu

Post on 14-Apr-2017

439 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Angular js architecture (v1.4.8)

Angular JS v1.4.8

TECH SESSION Lapusneanu Gabi Costel

Page 2: Angular js architecture (v1.4.8)

Key Features

01 Modules

02

03

Data Binding

Expressions

04Services

05Directives

Controllers 06

Page 3: Angular js architecture (v1.4.8)

function module(name, requires, configFn)essions

name === 'hasOwnProperty'

What is a Module?

01

02

04

You can think of a module as a container for the different parts of your app – controllers, services, filters, directives, etc.

Creation Retrieval

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

Signature

Page 4: Angular js architecture (v1.4.8)

Basic Module (Steps)

01Place the script at the bottom of the page.

02Place ng-*app to the

root of your application.*["ng-", "data-ng-", "ng:", "x-ng-"]

03Create the ng-app

module.

Page 5: Angular js architecture (v1.4.8)

Basic Module (Code)

Angular JS1 + 2 = 3

Page 6: Angular js architecture (v1.4.8)

Basic Module (Bootstrap)

As a best practice, consider adding an ng-strict-di directive on the same element as ng-app

Angular initializes automatically upon DOMContentLoaded event or when the angular.js script is evaluated if at that time document.readyState is set to 'complete'. At this point Angular looks for the ng-app directive which designates your application root.

You should call angular.bootstrap() after you've loaded or defined your modules. You should not use the ng-app directive when manually bootstrapping your app.

If window.name contains prefix NG_DEFER_BOOTSTRAP! when angular.bootstrap is called, the bootstrap process will be paused until angular.resumeBootstrap() is called.

A

M

D

Page 7: Angular js architecture (v1.4.8)

Basic Module (Instance)

Page 8: Angular js architecture (v1.4.8)

Basic Module (Compile)

Signature

Page 9: Angular js architecture (v1.4.8)

Dependency Injection (DI)

The Angular injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested.

Dependency Annotation

1

2

3

$inject Property Annotation

Inline

Preferred way

Inferred Implicit

Annotation

Only works if code is not minified/obfuscated (is disallowed when the injector is in strict mode).

Dependencies are injected based on the order they are declared within $inject array.

Page 10: Angular js architecture (v1.4.8)

Data Binding

Data-binding in Angular apps is the automatic synchronization of data between the model and view components.

The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application.

The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa..

A binding is denoted by double-curlies {{ }} or by ngBind directive.

It is preferable to use ngBind instead of {{ expression }}, or ng-cloak with {{expression}}. For better performance you can use One-Time Binding ::.

Page 11: Angular js architecture (v1.4.8)

Expressions

AngularJS expressions are much like JavaScript expressions. They can contain literals, operators and variable.

{{expression}}

Angular JS1 + 2 = {{1 + 2}}1 + 2 = 3

//expression//

Page 12: Angular js architecture (v1.4.8)

ServiceValue/

Constant

Factory Provider

Services

Services are objects whose API is defined by the developer writing the service.

Page 13: Angular js architecture (v1.4.8)

Directives (specialized objects)

Directives are used to extend HTML.

DirectiveTypes

E

AC

MComment:

<!— directive: my-directive exp -->

Element name (default): <my-directive></my-directive>

Attribute (default): <div my-directive="exp"></div>

Class: <div class="my-directive:exp;“/>

Directive Definition Object

In the DOM we refer to directives by lower-case forms, in code we refer to directives by their case-sensitive camelCase normalized.

Page 14: Angular js architecture (v1.4.8)

Execution Order

Page 15: Angular js architecture (v1.4.8)

Propagation of Events

Page 16: Angular js architecture (v1.4.8)

Time Directive (DEMO)

Page 17: Angular js architecture (v1.4.8)

THANK YOU!