1) Angular JS = Used In Single Page Application (SPA). 2) It is very powerful JavaScript i!rary. i!rary. ") It e#tends $%& '& Attri!utes and a*e responsive User Action. +,div class=-ead- ng/0=-- 3) Angular JS is open source 4e! application 5raewor*. 5eatures6/ 7) Angular JS is powerful JavaScript developent fraewor* to 8reate 9I8$ Internet Application (9IA). :) Angular JS provides developer ption to write 8lient Side Application (Using JavaScript) in a clean &;8 (&odel ;iew 8ontroller) 8ontroller) way. way. <) It cross/!rowser 8opati!ility. 8opati!ility. Angular JS andles JavaScript code suita!le sui ta!le for eac !rowser.
verall a!ove Points I can Say6 00 Angular JS is open Source fraewor* to !uild large scale and ig perforance we! application wile *eeping te as easy/to/aintain.
8ore 5eatures6 / 1) 'ata/inding6 'ata/inding6 It autoatic autoatic syncro syncroni>ati ni>ation on of data !etween !etween odel and view 8oponents. 2) Scope6 %ese are are o!?ect o!?ect tat tat refers refers to to &odel. &odel. %ey act as as glue !etween !etween 8ontroller and view. ") 8ontroller 8ontroller66 It is JavaScript 5unction 5unction tat tat are !ounds to particula particularr Scope. 3) Services6 Services6 Angular JS coe coe wit several several uilt/in uilt/in Services Services for e#aple e#aple @ttp @ttp to a*e an &$ttp9eBuests. %ese are singleton o!?ect wi c are Instantiated only once in App. 7) 5ilters6 %ese select a su!set of ite fro an array and return return into new Array. Array. :) 'irectives6 'irectives6 'irective 'irectives s are ar*ers ar*ers for '& eleents eleents li*e (Cleent (CleentsD sD attri!utesD 8SS and ore). It is used for create 8usto $tl %ag %ag tat serves as newD custo 4idgets. Angular JS as !uilt/in directives li*e (ng/appD ng/ odel). <) %eplate6 %ese are te rendered rendered view wit inforation inforation fro te controller controller and odel. It can !e single Ele (inde#.tl) or ultiple view wit one page using FPartial-. G) 9outing6 9outing6 It It is concept concept of switcing switcing ;iews. ;iews. H) &odel ;iew ;iew 4atever6 4atever6 &;8 is used used for design patter pattern n for dividing applicat application ion into dierent parts li*e (&odelD viewD 8ontroller). Angular JS doesn-t need &;8 structure in traditional senseD !ut it rater soeting close to &;/;& (&odel ;iew or ;iew &odel). &odel ;iew 4atever. 4atever.
1) 1) 'eep 'eep lin* lin*in ing6 g6 'eep 'eep in* in*in ing g all allow ows s to enco encode de te te appl applic icat atio ion n stat state e in U9 so tat can !e !oo*ar*ed. %e application can !e restored fro te U9 to te sae state. 11) 11) 'epe 'epend nden ency cy In?e In?ect ctio ion6 n6 An Angu gula larr JS as as !ui !uilt lt/i /in n depe depend nden ency cy In?e In?ect ctio ion n su!syste tat elps te developers !y a*ing application easy to developD test and understand.
Advantages of AngularJS:1) AngularJS AngularJS provides capa!ilit capa!ility y to create create Single Page Page Application Application in a very clean and aintaina!le way. 2) AngularJS AngularJS provides provides data !inding !inding capa!ility capa!ility to to $%& tus tus giving user user a ric and responsive e#perience ") AngularJ AngularJS S code code is unit unit testa testa!le. !le. 3) AngularJS AngularJS uses dependency dependency in?ection in?ection and a*e use of separation separation of concer concerns. ns. 7) AngularJS AngularJS provides reusa!le reusa!le coponen coponents. ts. 4it AngularJSD AngularJSD developer developer write less code and get ore functionality. functionality. :) In AngularJSD AngularJSD views are are pure tl tl pagesD and contro controllers llers written written in JavaScript JavaScript do te !usiness processing. <) n top of everyting everytingDD AngularJS AngularJS applications applications can run on all all a?or !rowsers !rowsers and sart pones including Android and iS !ased ponesKta!lets. Disadvantages of AngularJS: %oug AngularJS coes wit lots of plus points !ut sae tie we sould consider te following pointsL Not Secure L eing JavaScript only fraewor*D application written in AngularJS
are not safe. Server side autentication and autori>ation is ust to *eep an application secure. Not degradable L If your application user disa!les JavaScript ten user will ?ust
see te !asic page and noting ore.
Angular JS Components: %ey are tree ain part of coponents6 coponents6 1) Ng-app 6 %is directive deEnes and lin*s to an Angular JS application to $%&. 2) Ng-model 6 %is directive !inds te values of Angular JS Application data to $%& Input controls. ") Ng-binds 6 %is 'irectives 'i rectives !inds te Angular An gular JS data to $%& %ag. %ag.
1) Point Point to Angular Angular JS JS App: App: 4en we place ng/app at tat tie Angular JS
application startK lin* to tl page.+C#aple6 ,!ody ng/app = MyappN 6So ere &odule is yapp6
2) ie!:
So !elow Synta# it say ;iew. a) Og/contro Og/controller ller tells to Angular Angular JS wat contro controller ller to use wit wit tis view. view. !) ello%o.title o.title tells to Angular JS write &odel &odel value to $%& page at tis location. View :
,div ng/controller = $ello8ontroller
,24elcoe ,2 4elcoe QQello%o.titleRR to te world of %utorialspoint,K2 %utorialspoint ,K2 ,Kdiv
") Cont Contro roll ller er:: elow Synta#D $ere te code registered wit controller function
nae called T$ello8ontrollerF in angular odule naed yapp. So &odule and 8ontroller can learn in ne#t capter wit is ar*ed in igt lue 8olor. So ere 8ontroller function +$ello8ontroller is registered in angular via angular odule() and .controller() function call. #Scope: is a Paraeter passed to controller function is called T&odel-.
%e controller function add ello%o ello%o JavaScript o!?ectD and in tat !?ect it add a title Eeld. 3) ,script 7)
angular.odule odule((yapp yappDD +)
:) <)
.controller controller(($ello8ontroller $ello8ontrollerDD function function((@scope @scope)) Q
G)
@scope.ello%o = QR
H)
@scope.ello%o ello%o..title = AngularJS AngularJS
1 )
R)
11) ,Kscript
$) %&en t&e page is loaded loaded in t&e bro!ser bro!ser'' follo!ing t&ings t&ings &appen ( •
$%& docuent docuent is loaded loaded into te !rowser !rowserDD and evaluate evaluated d !y te !rowser !rowser.. AngularJS JavaScript Ele is loadedD te angular global o!?ect is created. Oe#tD JavaScript wic registers registers controll controller er functions functions is e#ecuted. e#ecuted.
•
Oe#t AngularJS scans troug te $%& to loo* for AngularJS apps and views. nce nce view is locatedD locatedD it connect connects s tat view to te corres correspon pondin ding g control controller ler function.
•
Oe#tD AngularJS e#ecutes te controller functions. It ten renders te views wit data fro te odel populated !y te controller. %e page is now ready.
&odel ;iew 8ontroller or &;8 as it is popularly calledD is a software design pattern for developing we! applications. A &odel ;iew 8ontroller pattern is ade up of te following tree parts L
&odel L It is te lowest level of te pattern responsi!le for aintaining data. ;iew L It is responsi!le for displaying all or a portion of te data to te user. 8ontroller L It is a software 8ode tat controls te interactions !etween te &odel and ;iew.
&;8 is popular !ecause it isolates te application logic fro te user interface layer and supports separation of concerns. %e controller receives all reBuests for te application and ten wor*s wit te odel to prepare any data needed !y te view. %e view ten uses te data prepared !y te controller controller to generate a Enal presenta!le response. %e &;8 a!straction can !e grapically represented as follows. AngularJS &;8 %e &odel %e odel is responsi!le for anaging application data. It responds to te reBuest fro view and to te instructions fro controller to update itself. itself. %e ;iew A presentation of data in a particular foratD triggered !y te controllerVs decision to present te data. %ey are script/!ased teplate systes suc as JSPD ASPD P$P and very easy to integrate wit AJA tecnology. tecnology. %e 8ontroller %e controller responds to user input and perfors interactions on te data odel odel o!?ects. %e controller receives inputD validates itD and ten perfors !usiness operations tat odify te state of te data odel. AngularJS is a &;8 !ased fraewor*. In te coing captersD we will see ow AngularJS uses &;8 etodology. etodology. o! AngularJS integrates !it& *+,:
1) Og/app6 %is %is directives directives deEnes deEnes te starting starting te Angular Angular JS application. application. 2) Og/odel6 Og/odel6 %is directives directives creates creates odel varia!le called called MAnyting MAnytingN N wic can !e used in tl page and witin ,div te ng/app located. ") Og/!inds6 Og/!inds6 %is directives directives old te odel odel ;aria!le ;aria!le value and and display te te#t te#t wen te user type in te#t!o#. 3) 8losing ,Kdiv tag indicates indicates Angular Angular JS Application Application 8losed. 8losed. AngularJS Directives: Directives:
Angular JS 'irectives are used to e#tend $%& Cleent. %ese are special attri!utes start wit ng/preE#. Soe directives are 1) ng/app6 %ese directive start te Angular JS Application 2) ng/init6 %ese directive initiali>e application 'ata ") ng/odel6 %ese directive deEnes odel tat is a varia!le in angular JS. 3) ng/repeat6 %ese directive repeat $%& eleent for eac ite in angular JS. Ng-app: Og/App start te angular JS Application. It deEnes te root eleent. It
autoatically initiali>e and start te application wen we! page containing Angular JS Application Is loaded. It also used to load various Angular JS &odules in angular JS Application.
,div ng/app = ... ,Kdiv
Ng-init: Og/init 'irective initiali>e te Angular JS Application 'ata. It put te values
to varia!le to !e used in te application. ,div ng/app = ng/init = countries = +Qlocale6Ven/USVDnae6VUnited StatesVRD Qlocale6Ven/ WVDnae6VUnited XingdoVRD Qlocale6Ven/59VDnae6V5 Qlocale6Ven/59VDnae6V5ranceVR ranceVR ... ,Kdiv
Ng-model: Og/odel directive deEnes te odelKvaria!le to !e used in Angular JS
Apps. ,div ng/app = ... ,pCnter ,p Cnter your Oae6 ,input type = te#t ng/odel = nae nae,Kp ,Kp ,Kdiv
Ng-.epeat: Og/repeat directive is to create $%& Cleent for eac ite wen te
application data is need an eleent. ,div ng/app = ... ,pist ,p ist of 8ountries wit locale 6, 6, Kp
,ol ,li ng/repeat = country in countries countries QQ V8ountry6 V Y country country.nae .nae Y VD ocale6 V Y country country.locale .locale RR ,Kli ,Kol
,Kdiv
/0ample for Angular JS Directives: ,tl
,ead ,titleAngularJS ,title AngularJS 'irectives,Ktitle 'irectives,Ktitle ,Kead
,!ody ,1Saple ,1 Saple Application,K1 Application,K1
,div ng/app = ng/init = countries = +Qlocale6Ven/USVDnae6VUnited StatesVRD Qlocale6Ven/ WVDnae6VUnited XingdoVRD Qlocale6Ven/59VDnae6V5 Qlocale6Ven/59VDnae6V5ranceVR ranceVR ,pCnter ,p Cnter your Oae6 ,input type = te#t ng/odel = nae nae,Kp ,Kp ,p$ello ,p $ello ,span ng/!ind = nae nae,Kspan ,Kspan,Kp ,pist ,p ist of 8ountries wit locale6,Kp locale6 ,Kp
,ol ,li ng/repeat = country in countries countries QQ V8oun V8ountry6 try6 V Y countr country y.nae Y VD ocale6 V Y country.locale RR ,Kli ,Kol ,Kdiv
,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript
,K!ody ,Ktl
Angular JS /0pression: /0pression:
C#pressions are used to !ind application data to tl. C#pressions are written inside dou!le !races li*e QQe#pressionRR. C#pressions !eaves in sae way as ng/!ind directives. AngularJS application e#pressions are pure JavaScript e#pressions and outputs te data were tey are used. Using Ou!ers6 ,p$ello QQcost 0 productRR ,Kp Using String6 ,p5irstnae6 QQstudent.ErstnaeRR ,Kp ,pastnae6 QQstudent.lastnaeRR ,Kp Using !?ect6 ,p9oll Oo6 QQstudent.rollnoRR ,Kp Using Array6 ,par*s QQar*s +3RR ,Kp. ,tl
,ead ,titleAngularJS ,title AngularJS C#pressions,Ktitle C#pressions,Ktitle ,Kead
,!ody ,1Saple ,1 Saple Application,K1 Application,K1
,div ng/app = ng/init = Buantity = 1cost = " student = QErstnae6V&aesVDlastnae6VParasarVDrollno611Rar*s = +GDH D<7D<"D: QErstnae6V&aesVDlastnae6VParasarVDrollno611Rar*s D<7D<"D: ,p$ello ,p $ello QQstudent.Erstnae Y Y student.lastnaeRR,Kp student.lastnaeRR,Kp ,pC#pense ,p C#pense on oo*s 6 QQcost 0 BuantityRR 9s,Kp 9s ,Kp
,p9oll ,p 9oll Oo6 QQstudent.rollnoRR,Kp QQstudent.rollnoRR,Kp ,p&ar*s(&at)6 ,p &ar*s(&at)6 QQar*s+"RR,Kp QQar*s+"RR,Kp ,Kdiv
,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript
,K!ody ,Ktl
Angular JS Controller:
Angular JS &ainly relies on 8ontroller to control te Zow of data in application. %e controller is deEned using ng/controller directive. %e controller is JavaScript o!?ect containing attri!uteKproperties and function. Cac controller accept @scope as a paraeter wic refers to applicationKodule tat controller is to control. ,div ng/app = ng/controller = student8ontroller student8ontroller ... ,Kdiv
$ere we declared a controller FStudent 8ontroller- using ng/controller directive. ,script function student8ontroller function student8ontroller((@scope @scope)) Q
@scope.student = Q @scope.
ErstOae6 &aes ErstOae6 &aesDD
lastOae6 Parasar lastOae6 ParasarDD
fullOae66 function fullOae function() () Q var student!?ect var student!?ect
student!?ect = @scope @scope..student student return student!?ect return student!?ect..ErstOae Y Y student!?ect student!?ect..lastOae lastOae R R R
,Kscript
1) Student8ontr Student8ontroller oller is deEned deEned as a JavaScript JavaScript !?ect !?ect wit @scope @scope as a arguent. 2) @scope @scope is reference reference to application application wic wic is to use te student8ontro student8ontroller ller o!?ect. ") @scope.stude @scope.student nt is property property for Student8o Student8ontro ntroller ller.. 3) 5irstnae irstnae and lastnae lastnae are property property for @scope.st @scope.student udent and Oow @scope.student is !?ect. 7) $ere fullnae fullnae is a functio function n of @scope. @scope.studen studentt o!?ect o!?ect and wose wose tas* to to return te co!ined nae. :) 5ullnae function function we-re we-re getting te student student o!?ect and and ten return return te co!ined value. <) As a noteD noteD we can also also deEned deEned controller controller o!?ect o!?ect in separat separate e JS Ele. Oow we can use Student8ontroller o!?ect in ng/odel to get te values fro controller !y using te e#pression. Cnter Erst Cnter Erst nae6 nae6 ,input type = te#t te#t ng ng//odel = student.ErstOae student.ErstOae, ,!r !r Cnter last last nae nae66 ,input type = te#t te#t ng ng//odel = student.lastOae student.lastOae, ,!r !r ,!r [ou [ ou are are entering6 entering6 QQ QQstudent student..fullOae fullOae()RR ()RR
$ere student.Erstnae and student.lastnae were place to ng/odel and in page it will sow default values wic is assigned in JS Ele. And fullnae() etod can give in two ways a) e#pression or !) ng/!inds. /0ample for ng-controller Angular JS Controller): ,tl
,ead ,titleAngular ,title Angular JS 8ontroller,Ktitle 8ontroller,Ktitle ,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript ,Kead
,!ody ,2AngularJS ,2 AngularJS Saple Application,K2 Application,K2
,div ng/app = ainApp ng/controller = student8ontroller student8ontroller Cnter Erst nae6 ,input type = te#t ng/odel = student.ErstOae student.ErstOae,!r,!r ,!r,!r Cnter last nae6 ,input type = te#t ng/odel = student.lastOae student.lastOae,!r ,!r
,!r
[ou [ ou are entering6 QQstudent.fullOae()RR ,Kdiv
,script var ainApp var ainApp = angular angular..odule odule((ainApp ainAppDD +)
ainApp..controller ainApp controller((Vstudent8ontrollerV Vstudent8ontrollerVDD function function((@scope @scope)) Q
@scope.student = Q @scope.
ErstOae6 &aes ErstOae6 &aesDD
lastOae6 Parasar lastOae6 ParasarDD
fullOae66 function fullOae function() () Q var student!?ect var student!?ect
student!?ect = @scope @scope..student student return student!?ect return student!?ect..ErstOae Y Y student!?ect student!?ect..lastOae lastOae R R R) ,Kscript
,K!ody ,Ktl
Angular JS ilters:
5ilter are used to cange odify te data and te clu!!ed into e#pression or directives using pipe caracter. 5ollowing is te list coonly used in directives. 1) 2) ") 3) 7)
Uppercase Uppercase 6 It 8onvert 8onvert te %e#t %e#t into Upperc Uppercase ase owercase6 owercase6 it convert convert te te te#t te#t into lowercase lowercase 8urrency 8urrency66 It place currency currency sy!ol sy!ol !efore nueric nueric value. value. 5ilter6 ilter6 Elter te array array to a su!set su!set of it !ased on on provided provided criteria. criteria. rder [ [6 orders te array array !ased on provided provided criteria. criteria.
3ppercase ilter:
Add uppercase Elter to an e#pression using pipe caracter. $ere weVve added uppercase Elter to print student nae in all capital letters. ,o!ercase ilter:
Add lowercase Elter to an e#pression using pipe caracter. caracter. $ere weVve added lowercase Elter to print student nae in all lowercase letters. Currenc4 ilter:
Add currency Elter to an e#pression returning nu !er using pipe pi pe caracter. caracter. $ere weVve added currency Elter to print fees using currency forat. ilter:
% display only reBuired user values. 5rderb4: %o %o order values !y nueric. ,tl
,ead ,titleAngular ,title Angular JS 5ilters,Ktitle 5ilters,Ktitle ,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript ,Kead
,!ody ,2AngularJS ,2 AngularJS Saple Application,K2 Application,K2 ,div ng/app = ainApp ng/controller = student8ontroller student8ontroller ,ta!le !order = ,tr ,tdCnter ,td Cnter Erst nae6,Ktd nae6,Ktd ,td,input type = te#t ng/odel = student.ErstOae student.ErstOae,Ktd ,Ktd ,Ktr
,tr ,tdCnter ,td Cnter last nae6 ,Ktd ,td,input type = te#t ng/odel = student.lastOae student.lastOae,Ktd ,Ktd ,Ktr
,tr ,tdCnter ,td Cnter fees6 ,Ktd ,td,input type = te#t ng/odel = student.fees student.fees,Ktd ,Ktd ,Ktr
,tr ,tdCnter ,td Cnter su!?ect6 ,Ktd ,td,input type = te#t ng/odel = su!?ectOae su!?ectOae,Ktd ,Ktd ,Ktr ,Kta!le ,!rK
,ta!le !order = ,tr ,tdOae ,td Oae in Upper 8ase6 ,Ktd,td ,Ktd,tdQQstudent.fullOae() QQstudent.fullOae() \ uppercaseRR,Ktd uppercaseRR,Ktd ,Ktr
,tr ,tdOae ,td Oae in ower 8ase6 ,Ktd,td ,Ktd,tdQQstudent.fullOae() QQstudent.fullOae() \ lowercaseRR,Ktd lowercaseRR,Ktd ,Ktr
,tr ,tdfees6 ,td fees6 ,Ktd,td ,Ktd,tdQQstudent.fees QQstudent.fees \ currencyRR ,Ktd ,Ktr
,tr ,tdSu!?ect6 ,td Su!?ect6,Ktd ,Ktd
,td ,ul ,li ng/repeat = su!?ect in student.su!?ects \ Elter6 su!?ectOae \ordery6Var*sV \ordery6Var*sV QQ su!?ect.nae Y VD ar*s6V Y su!?ect.ar*s RR
,Kli ,Kul ,Ktd ,Ktr ,Kta!le
,Kdiv
,script var ainApp var ainApp = angular angular..odule odule((ainApp ainAppDD +)
ainApp..controller ainApp controller((Vstudent8ontrollerV Vstudent8ontrollerVDD function function((@scope @scope)) Q
@scope.student = Q @scope.
ErstOae6 &aes ErstOae6 &aesDD
lastOae6 Parasar lastOae6 ParasarDD
fees67 fees6 7DD
su!?ects6+ su!?ects 6+ Qnae nae66VPysicsV VPysicsVDDar*s ar*s66< <RD RD Qnae nae66V8eistryV V8eistryVDDar*s ar*s66G GRD RD Qnae nae66V&atV V&atVDDar*s ar*s66:7 :7R R D
fullOae66 function fullOae function() () Q var student!?ect var student!?ect
student!?ect = @scope @scope..student student return student!?ect return student!?ect..ErstOae Y Y student!?ect student!?ect..lastOae lastOae R R R) ,Kscript
,K!ody
,Ktl
AngularJS Sample Application
Cnter Erst nae6 Cnter last nae6 Cnter fees6 Cnter su!?ect6 Oae in Upper 8ase6 Oae in ower 8ase6 fees6
&A$CS$ PA9AS$A9 aes parasar @7. &atD ar*s6:7 PysicsD ar*s6< 8eistryD ar*s6G •
Su!?ect6
• •
Angular JS *+, D5+:
5ollowing 'irectives !ind te application data to attri!utes of $tl 'o Cleents. 1) ng/disa!led 2) ng/sow ") ng/ide 3) ng/clic* Ng-disabled: Add ng/disa!led attri!ute to a $%& !utton and pass it a odel. ind
te odel to a cec*!o# and see te variation. Ng-s&o!: Add ng/sow attri!ute to a $%& !utton and pass it a odel. ind te odel to a cec*!o# and see te variation. Ng-&ide: Add ng/ide attri!ute to a $%& !utton and pass it a odel. ind te odel to a cec*!o# and see te variation. Ng-clic6: Add ng/clic* attri!ute to a $%& !utton and update a odel. ind te odel to tl and see te variation. ,tl
,ead ,titleAngularJS ,title AngularJS $%& '&,Ktitle '&,Ktitle ,Kead
,!ody ,2AngularJS ,2 AngularJS Saple Application,K2 Application,K2 ,div ng/app =
,ta!le !order = ,tr ,td,input type = cec*!o# ng/odel = ena!le'isa!leutton ena!le'isa!leutton 'isa!le utton,Ktd utton,Ktd ,td,!utton ng/disa!led = ena!le'isa!leutton ena!le'isa!leutton 8lic* &e,K!utton,Ktd &e,K!utton,Ktd ,Ktr
,tr ,td,input type = cec*!o# ng/odel = sow$ide1 sow$ide1 Sow utton,Ktd utton,Ktd ,td,!utton ng/sow = sow$ide1 sow$ide1 8lic* &e,K!utton,Ktd &e,K!utton,Ktd ,Ktr
,tr ,td,input type = cec*!o# ng/odel = sow$ide2 sow$ide2 $ide utton,Ktd utton,Ktd ,td,!utton ng/ide = sow$ide2 sow$ide2 8lic* &e,K!utton,Ktd &e,K!utton,Ktd ,Ktr
,tr ,td,p % %otal otal clic*6 QQ clic*8ounter RR,Kp,Ktd RR,Kp,Ktd ,td,!utton ng/clic* = clic*8ounter = clic*8ounter Y 1 18lic* &e,K!utton,Ktd &e,K!utton,Ktd ,Ktr ,Kta!le
,Kdiv
,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript
,K!ody ,Ktl
AngularJS Sample Application
'isa!le utton
8lic* &e
Sow utton $ide utton
%otal %otal clic*6 12
8lic* &e 8lic* &e
Angular JS +odules:
Angular JS support &odular approac. &odular is used to separate logic say serviceD applicationD controller etc. and it will *eep te code clean. 4e deEne odular in separate JS Ele and te nae te as per te odule.?s. %ey are two JS Ele one is Application and 8ontroller JS Ele. 1) Application +odule: Application odule is used to initiali>e te application wit controller. 2) Controller +odule: 8ontroller &odule is i s used to deEne te controller. controller. Application +odule:
+%is array contain dependent &odule Synta#6 var ainapp = angular.odule(Fyapp-D angular.odule(Fyapp-D +) + Application &odule Oae ng/app=-yapp-. $ere weVve declared an application m4App odule using +angular.odule +angular.odule function. 4eVve passed an epty array to it. %is array generally contains dependent odules. Controller +odule: Syntax:
ainApp..controller ainApp controller((student8ontroller student8ontrollerDD function function((@scope @scope)) Q
@scope. @scope.student = Q
ErstOae6 &aes ErstOae6 &aesDD
lastOae6 Parasar lastOae6 ParasarDD
fees67 fees6 7DD
su!?ects6+ su!?ects6+ Qnae nae66VPysicsV VPysicsVDDar*s ar*s66< <RD RD Qnae nae66V8eistryV V8eistryVDDar*s ar*s66G GRD RD Qnae nae66V&atV V&atVDDar*s ar*s66:7 :7RD RD Qnae nae66VCnglisV VCnglisVDDar*s ar*s66<7 <7RD RD Qnae nae66V$indiV V$indiVDDar*s ar*s66:< :
fullOae66 function fullOae function() () Q var student!?ect var student!?ect
student!?ect = @scope @scope..student student return student!?ect return student!?ect..ErstOae Y Y student!?ect student!?ect..lastOae lastOae R R
R)
$ere we declared 8ontroller Student8ontroller odule to ainapp.controller() 5unction.
Use &odules 6 ,div ng/app = ainApp ng/controller = student8ontroller student8ontroller ... ,script src = ainApp.?s ainApp.?s,Kscript ,Kscript ,script src = student8ontroller.?s student8ontroller.?s,Kscript ,Kscript
,Kdiv
$ere weVve used application odule using ng/app directive and controller using ng/ controller controller directive. directive. 4eVve iported iported ainApp.?s ainApp.?s and student8ontr student8ontroller oller.?s .?s in te ain tl page.
Angular JS orms:
Angular JS enrices for Elling and validation. $ere we use ng/clic* event for angular JS clic* !utton and use #dirt4 and #invalid for validation in sealess way. way. In for validatio validation n we use 7novalida 7novalidation8 tion8 to disa!le !rowser speciEc validation. 5or controls controls a*e eavy use on Angular A ngular JS Cvents.
/vents:
Og/clic* Og/d!l/clic* Og/ouseenter Og/ouseleave Og/overover Og/ouseup Og/ousedown Og/ouseove Og/*eyup Og/*eydown Og/cange Og/*eypress
alidate Data:
5ollowing can !e used to trac* error6
1) #dir #dirt4 t4:: states te value as canged. 2) #inv #inval alid id:: states tat value entered is invalid ") #err #error or:: states tat e#act error.
,tl ,ead ,titleAngular ,title Angular JS 5ors,Ktitle 5ors,Ktitle ,script src = ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s ttp6KKa?a#.googleapis.coKa?a#Kli!sKangular?sK1.".13Kangular.in.?s,Kscript ,Kscript
,style
ta!leD t D td Q ta!leD
!order6 1p# !order6 1p# solid solid grey grey
!order/collapse !order/ collapse66 collapse collapse
padding6 7p# padding6 7p# R
ta!le tr6 tr6nt nt//cild cild((odd odd)) Q
!ac*ground/color !ac*ground/ color66 ]f2f2f2 R
ta!le tr6 tr6nt nt//cild cild((even even)) Q
!ac*ground/color !ac*ground/ color66 ] R ,Kstyle
,Kead ,!ody
,2AngularJS ,2 AngularJS Saple Application,K2 Application,K2 ,div ng/app = ainApp ng/controller = student8ontroller student8ontroller
,for nae = student5or novalidate novalidate ,ta!le !order = ,tr ,tdCnter ,td Cnter Erst nae6,Ktd nae6,Ktd ,td,input nae = Erstnae type = te#t ng/odel = ErstOae reBuired reBuired ,span style = color color66red red ng/sow = student5or student5or.Erstnae.@dirty .Erstnae.@dirty ^^ student5or.Erstnae.@invalid student5or.Erstnae.@invalid ,span ng/sow = student5or.E student5or.Erstnae.@error rstna
[email protected] .reBuired 5irst Oae is reBuired.,Kspan reBuired. ,Kspan ,Kspan ,Ktd ,Ktr
,tr ,tdCnter ,td Cnter last nae6 ,Ktd ,td,input nae = lastnae type = te#t ng/odel = lastOae reBuired reBuired ,span style = color color66red red ng/sow = student5or student5or.lastnae.@dirty .lastnae.@dirty ^^ student5or.lastnae.@invalid student5or.lastnae.@invalid ,span ng/sow = student5or.last student5or.lastnae.@error na
[email protected] .reBuired ast Oae is reBuired.,Kspan reBuired. ,Kspan ,Kspan ,Ktd ,Ktr
,tr ,tdCail6 ,td Cail6 ,Ktd,td,input nae = eail type = eail ng/odel = eail lengt = 1 reBuired reBuired ,span style = color color66red red ng/sow = student5or student5or.eail.@dirty .eail.@dirty ^^ student5or student5or.eail. .eail. @invalid @invalid ,span ng/sow = student5or.e student5or.eail.@error
[email protected] .reBuired Cail is reBuired.,Kspan reBuired.,Kspan ,span ng/sow = student5or.e
[email protected]ailInvalid eail address.,Kspan address.,Kspan ,Kspan ,Ktd ,Ktr
,tr ,td ,!utton ng/clic* = reset() reset() 9eset 9eset,K!utton ,K!utton ,Ktd ,td ,!utton ng/disa!led = student5or.E student5or.Erstnae.@dirty rstnae.@dirty ^^ student5or.Erstnae.@invalid student5or.Erstna e.@invalid \\ student5or.las student5or.lastnae.@dirty tnae.@dirty ^^ student5or.lastnae.@invalid student5or.lastna e.@invalid \\ student5or.ea student5or.eail.@dirty il.@dirty ^^
student5or.eail.@invalid ng/clic* ng/clic*= =su!it() su!it() Su!it Su!it,K!utton ,K!utton ,Ktd ,Ktr
,Kta!le ,Kfor ,Kdiv
,script var ainApp var ainApp = angular angular..odule odule((ainApp ainAppDD +)
ainApp..controller ainApp controller((Vstudent8ontrollerV Vstudent8ontrollerVDD function function((@scope @scope)) Q
@scope.reset = function @scope. function()Q ()Q
@scope.ErstOae = &aes @scope. &aes
@scope.lastOae = Parasar @scope. Parasar
@scope.eail = &aesParasar_tutorialspoint.co @scope. &aesParasar_tutorialspoint.co R
@scope..reset @scope reset() () R) ,Kscript
,K!ody ,Ktl