Top Banner
MV* Framework and Components AngularJS
22

AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Aug 04, 2018

Download

Documents

phungduong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

MV* Framework and Components

AngularJS

Page 2: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Goals

ü  Understanding MVCü  Understanding MV* structure of AngularJSü  Understanding Two-way dynamic bindingü  Understanding Single-Page-Applicationsü  Understanding Declarative Approach of AngularJSü  Advantages of using AngularJSü  Component in AngularJS

AngularJS Basics 2

Page 3: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

MVC frameworks

Page 4: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

What is MVC

AngularJS Basics 4

In a typical MVC framework, developer has to code the update mechanism for view or model. However AngularJS framework automatically updates model (data) or view according to changes made in any one of them.

Page 5: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Problem of MVC

AngularJS Basics 5

MVC frameworks generally combines model with template and generate view. This approach has a major drawback when it comes to updating. This is One-way Binding

Page 6: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS

Page 7: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS

AngularJS Basics 7

AngularJS is an open-source Javascript MVC (or better MV*) framework created by Google to build dynamic web applications with a proper architecture. It enhances the capabilities of HTML and lets you create Single Page dynamic web apps.

The other popular JavaScript web frameworks are Backbone.js, Ember.js etc.

Page 8: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Single Page App (SPA)

8

Static Part

Dynamic Part

-  Single page is loaded-  All script resources are loaded

initially-  Partials are loaded depending on

routing scheme-  Data remains persistent until

reload

http://www.myapplication.com/loginhttp://www.myapplication.com/profile

AngularJS Basics

Page 9: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Single Page App (SPA)

AngularJS Basics 9

A single-page application (SPA), is a web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application.

Page 10: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS deals with the problem by continuously updating model and view on its own. This is two-way data binding

AngularJS : 2-way binding

AngularJS Basics 10

Page 11: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS : Declarative

DOM manipulation in AngularJS is controlled by directives which are identical to HTML tags and attributes in declaration. This Declarative Approach helps developer to understand the behavior of app easily.

AngularJS Basics 11

Page 12: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS : Structure

AngularJS Basics 12

Page 13: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS App

Page 14: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

App Initialization

AngularJS Basics 14

AppIni'aliza'oncanwebrokeninmul'plesteps1.   EmbeddingAngularJSlibrary2.   Se5ngupng-app3.   Bindingng-appwithAngularModule

Angular Core Library : angular.js Angular Route Library : angular-route.js Angular Cookies Library : angular-cookies.js Full list: https://docs.angularjs.org/misc/downloading

Page 15: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Angular Module : ng-app

AngularJS Basics 15

ng-appisanin-builtdirec'vewhichisusedto-  Ini@alizingAngularcodeinHTMLsec@on-  AGachingapar@cularangularmodule

<body ng-app = “MyApp”> - HTML var app = angular.module ( “MyApp” , [] ) - JS

Page 16: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Data Model : ng-model

AngularJS Basics 16

ng-modelisanin-builtdirec'vewhichisusedto-  bindinputdatatoscopeofcontroller

<input ng-model = “data”> - HTML $scope.data - JS

Page 17: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Angular Expressions

AngularJS Basics 17

AngularExpressionhavedifferentforms-  Whenusedinin-builtdirec@ve-  WhenusedanywhereinHTML

<input ng-model = “data”> <p>{{data}}</p> <img src={{data}} >

Page 18: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Controllers & Scope

Page 19: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Controllers : ng-controller

AngularJS Basics 19

Angular Controller is container for logic in certain section-  Multiple Controllers can be used-  App with no controllers also works -  Scope is bound to a particular controller

<div ng-controller = “homeCtrl”> </div> <div ng-controller = “menuCtrl”> </div>

Page 20: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

Define Controllers

AngularJS Basics 20

-  ControllersareaGachedtoangularmodule.-  Mul@plecontrollerscanbeaGachedusingchaining-  Controllersalsomaintainlistofdependencies

.controller ( “homeCtrl” , function ($scope) { $scope.data ; }) .controller ( “menuCtrl” , function ($scope) { $scope.data ; })

Page 21: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

$scope

AngularJS Basics 21

$scope contains all properties and methods of a controller scope .controller ( “homeCtrl” , function ($scope) { $scope.data ; }) .controller ( “menuCtrl” , function ($scope) { $scope.data ; })

Page 22: AngularJS - Cloud Object Storage · Problem of MVC AngularJS Basics 5 MVC frameworks generally combines model with template and generate view. This approach has a …

AngularJS Basics 22

Thank You