angular2.d.ts 297 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214
  1. // Type definitions for Angular v2.0.0-alpha.37
  2. // Project: http://angular.io/
  3. // Definitions by: angular team <https://github.com/angular/>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. // ***********************************************************
  6. // This file is generated by the Angular build process.
  7. // Please do not create manual edits or send pull requests
  8. // modifying this file.
  9. // ***********************************************************
  10. // angular2/angular2 depends transitively on these libraries.
  11. // If you don't have them installed you can install them using TSD
  12. // https://github.com/DefinitelyTyped/tsd
  13. ///<reference path="../es6-promise/es6-promise.d.ts"/>
  14. ///<reference path="../rx/rx.d.ts"/>
  15. // angular2/web_worker/worker depends transitively on these libraries.
  16. // If you don't have them installed you can install them using TSD
  17. // https://github.com/DefinitelyTyped/tsd
  18. ///<reference path="../es6-promise/es6-promise.d.ts"/>
  19. ///<reference path="../rx/rx.d.ts"/>
  20. // angular2/web_worker/ui depends transitively on these libraries.
  21. // If you don't have them installed you can install them using TSD
  22. // https://github.com/DefinitelyTyped/tsd
  23. ///<reference path="../es6-promise/es6-promise.d.ts"/>
  24. ///<reference path="../rx/rx.d.ts"/>
  25. interface Map<K,V> {}
  26. interface StringMap<K,V> extends Map<K,V> {}
  27. declare module ng {
  28. // See https://github.com/Microsoft/TypeScript/issues/1168
  29. class BaseException /* extends Error */ {
  30. message: string;
  31. stack: string;
  32. toString(): string;
  33. }
  34. interface InjectableReference {}
  35. }
  36. declare module ngWorker {
  37. // See https://github.com/Microsoft/TypeScript/issues/1168
  38. class BaseException /* extends Error */ {
  39. message: string;
  40. stack: string;
  41. toString(): string;
  42. }
  43. interface InjectableReference {}
  44. }
  45. declare module ngUi {
  46. // See https://github.com/Microsoft/TypeScript/issues/1168
  47. class BaseException /* extends Error */ {
  48. message: string;
  49. stack: string;
  50. toString(): string;
  51. }
  52. interface InjectableReference {}
  53. }
  54. /**
  55. * The `angular2` is the single place to import all of the individual types.
  56. */
  57. declare module ng {
  58. /**
  59. * Bootstrapping for Angular applications.
  60. *
  61. * You instantiate an Angular application by explicitly specifying a component to use as the root
  62. * component for your
  63. * application via the `bootstrap()` method.
  64. *
  65. * ## Simple Example
  66. *
  67. * Assuming this `index.html`:
  68. *
  69. * ```html
  70. * <html>
  71. * <!-- load Angular script tags here. -->
  72. * <body>
  73. * <my-app>loading...</my-app>
  74. * </body>
  75. * </html>
  76. * ```
  77. *
  78. * An application is bootstrapped inside an existing browser DOM, typically `index.html`. Unlike
  79. * Angular 1, Angular 2
  80. * does not compile/process bindings in `index.html`. This is mainly for security reasons, as well
  81. * as architectural
  82. * changes in Angular 2. This means that `index.html` can safely be processed using server-side
  83. * technologies such as
  84. * bindings. Bindings can thus use double-curly `{{ syntax }}` without collision from Angular 2
  85. * component double-curly
  86. * `{{ syntax }}`.
  87. *
  88. * We can use this script code:
  89. *
  90. * ```
  91. * @Component({
  92. * selector: 'my-app'
  93. * })
  94. * @View({
  95. * template: 'Hello {{ name }}!'
  96. * })
  97. * class MyApp {
  98. * name:string;
  99. *
  100. * constructor() {
  101. * this.name = 'World';
  102. * }
  103. * }
  104. *
  105. * main() {
  106. * return bootstrap(MyApp);
  107. * }
  108. * ```
  109. *
  110. * When the app developer invokes `bootstrap()` with the root component `MyApp` as its argument,
  111. * Angular performs the
  112. * following tasks:
  113. *
  114. * 1. It uses the component's `selector` property to locate the DOM element which needs to be
  115. * upgraded into
  116. * the angular component.
  117. * 2. It creates a new child injector (from the platform injector). Optionally, you can also
  118. * override the injector configuration for an app by
  119. * invoking `bootstrap` with the `componentInjectableBindings` argument.
  120. * 3. It creates a new `Zone` and connects it to the angular application's change detection domain
  121. * instance.
  122. * 4. It creates a shadow DOM on the selected component's host element and loads the template into
  123. * it.
  124. * 5. It instantiates the specified component.
  125. * 6. Finally, Angular performs change detection to apply the initial data bindings for the
  126. * application.
  127. *
  128. *
  129. * ## Instantiating Multiple Applications on a Single Page
  130. *
  131. * There are two ways to do this.
  132. *
  133. *
  134. * ### Isolated Applications
  135. *
  136. * Angular creates a new application each time that the `bootstrap()` method is invoked. When
  137. * multiple applications
  138. * are created for a page, Angular treats each application as independent within an isolated change
  139. * detection and
  140. * `Zone` domain. If you need to share data between applications, use the strategy described in the
  141. * next
  142. * section, "Applications That Share Change Detection."
  143. *
  144. *
  145. * ### Applications That Share Change Detection
  146. *
  147. * If you need to bootstrap multiple applications that share common data, the applications must
  148. * share a common
  149. * change detection and zone. To do that, create a meta-component that lists the application
  150. * components in its template.
  151. * By only invoking the `bootstrap()` method once, with the meta-component as its argument, you
  152. * ensure that only a
  153. * single change detection zone is created and therefore data can be shared across the applications.
  154. *
  155. *
  156. * ## Platform Injector
  157. *
  158. * When working within a browser window, there are many singleton resources: cookies, title,
  159. * location, and others.
  160. * Angular services that represent these resources must likewise be shared across all Angular
  161. * applications that
  162. * occupy the same browser window. For this reason, Angular creates exactly one global platform
  163. * injector which stores
  164. * all shared services, and each angular application injector has the platform injector as its
  165. * parent.
  166. *
  167. * Each application has its own private injector as well. When there are multiple applications on a
  168. * page, Angular treats
  169. * each application injector's services as private to that application.
  170. *
  171. *
  172. * # API
  173. * - `appComponentType`: The root component which should act as the application. This is a reference
  174. * to a `Type`
  175. * which is annotated with `@Component(...)`.
  176. * - `componentInjectableBindings`: An additional set of bindings that can be added to the app
  177. * injector
  178. * to override default injection behavior.
  179. * - `errorReporter`: `function(exception:any, stackTrace:string)` a default error reporter for
  180. * unhandled exceptions.
  181. *
  182. * Returns a `Promise` of {@link ApplicationRef}.
  183. */
  184. function bootstrap(appComponentType: /*Type*/ any, componentInjectableBindings?: Array<Type | Binding | any[]>) : Promise<ApplicationRef> ;
  185. /**
  186. * Declare reusable UI building blocks for an application.
  187. *
  188. * Each Angular component requires a single `@Component` and at least one `@View` annotation. The
  189. * `@Component`
  190. * annotation specifies when a component is instantiated, and which properties and hostListeners it
  191. * binds to.
  192. *
  193. * When a component is instantiated, Angular
  194. * - creates a shadow DOM for the component.
  195. * - loads the selected template into the shadow DOM.
  196. * - creates all the injectable objects configured with `bindings` and `viewBindings`.
  197. *
  198. * All template expressions and statements are then evaluated against the component instance.
  199. *
  200. * For details on the `@View` annotation, see {@link ViewMetadata}.
  201. *
  202. * ## Example
  203. *
  204. * ```
  205. * @Component({
  206. * selector: 'greet'
  207. * })
  208. * @View({
  209. * template: 'Hello {{name}}!'
  210. * })
  211. * class Greet {
  212. * name: string;
  213. *
  214. * constructor() {
  215. * this.name = 'World';
  216. * }
  217. * }
  218. * ```
  219. */
  220. class ComponentMetadata extends DirectiveMetadata {
  221. /**
  222. * Defines the used change detection strategy.
  223. *
  224. * When a component is instantiated, Angular creates a change detector, which is responsible for
  225. * propagating the component's bindings.
  226. *
  227. * The `changeDetection` property defines, whether the change detection will be checked every time
  228. * or only when the component tells it to do so.
  229. */
  230. changeDetection: ChangeDetectionStrategy;
  231. /**
  232. * Defines the set of injectable objects that are visible to its view dom children.
  233. *
  234. * ## Simple Example
  235. *
  236. * Here is an example of a class that can be injected:
  237. *
  238. * ```
  239. * class Greeter {
  240. * greet(name:string) {
  241. * return 'Hello ' + name + '!';
  242. * }
  243. * }
  244. *
  245. * @Directive({
  246. * selector: 'needs-greeter'
  247. * })
  248. * class NeedsGreeter {
  249. * greeter:Greeter;
  250. *
  251. * constructor(greeter:Greeter) {
  252. * this.greeter = greeter;
  253. * }
  254. * }
  255. *
  256. * @Component({
  257. * selector: 'greet',
  258. * viewBindings: [
  259. * Greeter
  260. * ]
  261. * })
  262. * @View({
  263. * template: `<needs-greeter></needs-greeter>`,
  264. * directives: [NeedsGreeter]
  265. * })
  266. * class HelloWorld {
  267. * }
  268. *
  269. * ```
  270. */
  271. viewBindings: any[];
  272. }
  273. /**
  274. * Directives allow you to attach behavior to elements in the DOM.
  275. *
  276. * {@link DirectiveMetadata}s with an embedded view are called {@link ComponentMetadata}s.
  277. *
  278. * A directive consists of a single directive annotation and a controller class. When the
  279. * directive's `selector` matches
  280. * elements in the DOM, the following steps occur:
  281. *
  282. * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor
  283. * arguments.
  284. * 2. Angular instantiates directives for each matched element using `ElementInjector` in a
  285. * depth-first order,
  286. * as declared in the HTML.
  287. *
  288. * ## Understanding How Injection Works
  289. *
  290. * There are three stages of injection resolution.
  291. * - *Pre-existing Injectors*:
  292. * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if
  293. * the dependency was
  294. * specified as `@Optional`, returns `null`.
  295. * - The platform injector resolves browser singleton resources, such as: cookies, title,
  296. * location, and others.
  297. * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow
  298. * the same parent-child hierarchy
  299. * as the component instances in the DOM.
  300. * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each
  301. * element has an `ElementInjector`
  302. * which follow the same parent-child hierarchy as the DOM elements themselves.
  303. *
  304. * When a template is instantiated, it also must instantiate the corresponding directives in a
  305. * depth-first order. The
  306. * current `ElementInjector` resolves the constructor dependencies for each directive.
  307. *
  308. * Angular then resolves dependencies as follows, according to the order in which they appear in the
  309. * {@link ViewMetadata}:
  310. *
  311. * 1. Dependencies on the current element
  312. * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary
  313. * 3. Dependencies on component injectors and their parents until it encounters the root component
  314. * 4. Dependencies on pre-existing injectors
  315. *
  316. *
  317. * The `ElementInjector` can inject other directives, element-specific special objects, or it can
  318. * delegate to the parent
  319. * injector.
  320. *
  321. * To inject other directives, declare the constructor parameter as:
  322. * - `directive:DirectiveType`: a directive on the current element only
  323. * - `@Host() directive:DirectiveType`: any directive that matches the type between the current
  324. * element and the
  325. * Shadow DOM root.
  326. * - `@Query(DirectiveType) query:QueryList<DirectiveType>`: A live collection of direct child
  327. * directives.
  328. * - `@QueryDescendants(DirectiveType) query:QueryList<DirectiveType>`: A live collection of any
  329. * child directives.
  330. *
  331. * To inject element-specific special objects, declare the constructor parameter as:
  332. * - `element: ElementRef` to obtain a reference to logical element in the view.
  333. * - `viewContainer: ViewContainerRef` to control child template instantiation, for
  334. * {@link DirectiveMetadata} directives only
  335. * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way.
  336. *
  337. * ## Example
  338. *
  339. * The following example demonstrates how dependency injection resolves constructor arguments in
  340. * practice.
  341. *
  342. *
  343. * Assume this HTML template:
  344. *
  345. * ```
  346. * <div dependency="1">
  347. * <div dependency="2">
  348. * <div dependency="3" my-directive>
  349. * <div dependency="4">
  350. * <div dependency="5"></div>
  351. * </div>
  352. * <div dependency="6"></div>
  353. * </div>
  354. * </div>
  355. * </div>
  356. * ```
  357. *
  358. * With the following `dependency` decorator and `SomeService` injectable class.
  359. *
  360. * ```
  361. * @Injectable()
  362. * class SomeService {
  363. * }
  364. *
  365. * @Directive({
  366. * selector: '[dependency]',
  367. * properties: [
  368. * 'id: dependency'
  369. * ]
  370. * })
  371. * class Dependency {
  372. * id:string;
  373. * }
  374. * ```
  375. *
  376. * Let's step through the different ways in which `MyDirective` could be declared...
  377. *
  378. *
  379. * ### No injection
  380. *
  381. * Here the constructor is declared with no arguments, therefore nothing is injected into
  382. * `MyDirective`.
  383. *
  384. * ```
  385. * @Directive({ selector: '[my-directive]' })
  386. * class MyDirective {
  387. * constructor() {
  388. * }
  389. * }
  390. * ```
  391. *
  392. * This directive would be instantiated with no dependencies.
  393. *
  394. *
  395. * ### Component-level injection
  396. *
  397. * Directives can inject any injectable instance from the closest component injector or any of its
  398. * parents.
  399. *
  400. * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type
  401. * from the parent
  402. * component's injector.
  403. * ```
  404. * @Directive({ selector: '[my-directive]' })
  405. * class MyDirective {
  406. * constructor(someService: SomeService) {
  407. * }
  408. * }
  409. * ```
  410. *
  411. * This directive would be instantiated with a dependency on `SomeService`.
  412. *
  413. *
  414. * ### Injecting a directive from the current element
  415. *
  416. * Directives can inject other directives declared on the current element.
  417. *
  418. * ```
  419. * @Directive({ selector: '[my-directive]' })
  420. * class MyDirective {
  421. * constructor(dependency: Dependency) {
  422. * expect(dependency.id).toEqual(3);
  423. * }
  424. * }
  425. * ```
  426. * This directive would be instantiated with `Dependency` declared at the same element, in this case
  427. * `dependency="3"`.
  428. *
  429. * ### Injecting a directive from any ancestor elements
  430. *
  431. * Directives can inject other directives declared on any ancestor element (in the current Shadow
  432. * DOM), i.e. on the current element, the
  433. * parent element, or its parents.
  434. * ```
  435. * @Directive({ selector: '[my-directive]' })
  436. * class MyDirective {
  437. * constructor(@Host() dependency: Dependency) {
  438. * expect(dependency.id).toEqual(2);
  439. * }
  440. * }
  441. * ```
  442. *
  443. * `@Host` checks the current element, the parent, as well as its parents recursively. If
  444. * `dependency="2"` didn't
  445. * exist on the direct parent, this injection would
  446. * have returned
  447. * `dependency="1"`.
  448. *
  449. *
  450. * ### Injecting a live collection of direct child directives
  451. *
  452. *
  453. * A directive can also query for other child directives. Since parent directives are instantiated
  454. * before child directives, a directive can't simply inject the list of child directives. Instead,
  455. * the directive injects a {@link QueryList}, which updates its contents as children are added,
  456. * removed, or moved by a directive that uses a {@link ViewContainerRef} such as a `ng-for`, an
  457. * `ng-if`, or an `ng-switch`.
  458. *
  459. * ```
  460. * @Directive({ selector: '[my-directive]' })
  461. * class MyDirective {
  462. * constructor(@Query(Dependency) dependencies:QueryList<Dependency>) {
  463. * }
  464. * }
  465. * ```
  466. *
  467. * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and
  468. * 6. Here, `Dependency` 5 would not be included, because it is not a direct child.
  469. *
  470. * ### Injecting a live collection of descendant directives
  471. *
  472. * By passing the descendant flag to `@Query` above, we can include the children of the child
  473. * elements.
  474. *
  475. * ```
  476. * @Directive({ selector: '[my-directive]' })
  477. * class MyDirective {
  478. * constructor(@Query(Dependency, {descendants: true}) dependencies:QueryList<Dependency>) {
  479. * }
  480. * }
  481. * ```
  482. *
  483. * This directive would be instantiated with a Query which would contain `Dependency` 4, 5 and 6.
  484. *
  485. * ### Optional injection
  486. *
  487. * The normal behavior of directives is to return an error when a specified dependency cannot be
  488. * resolved. If you
  489. * would like to inject `null` on unresolved dependency instead, you can annotate that dependency
  490. * with `@Optional()`.
  491. * This explicitly permits the author of a template to treat some of the surrounding directives as
  492. * optional.
  493. *
  494. * ```
  495. * @Directive({ selector: '[my-directive]' })
  496. * class MyDirective {
  497. * constructor(@Optional() dependency:Dependency) {
  498. * }
  499. * }
  500. * ```
  501. *
  502. * This directive would be instantiated with a `Dependency` directive found on the current element.
  503. * If none can be
  504. * found, the injector supplies `null` instead of throwing an error.
  505. *
  506. * ## Example
  507. *
  508. * Here we use a decorator directive to simply define basic tool-tip behavior.
  509. *
  510. * ```
  511. * @Directive({
  512. * selector: '[tooltip]',
  513. * properties: [
  514. * 'text: tooltip'
  515. * ],
  516. * host: {
  517. * '(mouseenter)': 'onMouseEnter()',
  518. * '(mouseleave)': 'onMouseLeave()'
  519. * }
  520. * })
  521. * class Tooltip{
  522. * text:string;
  523. * overlay:Overlay; // NOT YET IMPLEMENTED
  524. * overlayManager:OverlayManager; // NOT YET IMPLEMENTED
  525. *
  526. * constructor(overlayManager:OverlayManager) {
  527. * this.overlay = overlay;
  528. * }
  529. *
  530. * onMouseEnter() {
  531. * // exact signature to be determined
  532. * this.overlay = this.overlayManager.open(text, ...);
  533. * }
  534. *
  535. * onMouseLeave() {
  536. * this.overlay.close();
  537. * this.overlay = null;
  538. * }
  539. * }
  540. * ```
  541. * In our HTML template, we can then add this behavior to a `<div>` or any other element with the
  542. * `tooltip` selector,
  543. * like so:
  544. *
  545. * ```
  546. * <div tooltip="some text here"></div>
  547. * ```
  548. *
  549. * Directives can also control the instantiation, destruction, and positioning of inline template
  550. * elements:
  551. *
  552. * A directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at
  553. * runtime.
  554. * The {@link ViewContainerRef} is created as a result of `<template>` element, and represents a
  555. * location in the current view
  556. * where these actions are performed.
  557. *
  558. * Views are always created as children of the current {@link ViewMetadata}, and as siblings of the
  559. * `<template>` element. Thus a
  560. * directive in a child view cannot inject the directive that created it.
  561. *
  562. * Since directives that create views via ViewContainers are common in Angular, and using the full
  563. * `<template>` element syntax is wordy, Angular
  564. * also supports a shorthand notation: `<li *foo="bar">` and `<li template="foo: bar">` are
  565. * equivalent.
  566. *
  567. * Thus,
  568. *
  569. * ```
  570. * <ul>
  571. * <li *foo="bar" title="text"></li>
  572. * </ul>
  573. * ```
  574. *
  575. * Expands in use to:
  576. *
  577. * ```
  578. * <ul>
  579. * <template [foo]="bar">
  580. * <li title="text"></li>
  581. * </template>
  582. * </ul>
  583. * ```
  584. *
  585. * Notice that although the shorthand places `*foo="bar"` within the `<li>` element, the binding for
  586. * the directive
  587. * controller is correctly instantiated on the `<template>` element rather than the `<li>` element.
  588. *
  589. *
  590. * ## Example
  591. *
  592. * Let's suppose we want to implement the `unless` behavior, to conditionally include a template.
  593. *
  594. * Here is a simple directive that triggers on an `unless` selector:
  595. *
  596. * ```
  597. * @Directive({
  598. * selector: '[unless]',
  599. * properties: ['unless']
  600. * })
  601. * export class Unless {
  602. * viewContainer: ViewContainerRef;
  603. * templateRef: TemplateRef;
  604. * prevCondition: boolean;
  605. *
  606. * constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef) {
  607. * this.viewContainer = viewContainer;
  608. * this.templateRef = templateRef;
  609. * this.prevCondition = null;
  610. * }
  611. *
  612. * set unless(newCondition) {
  613. * if (newCondition && (isBlank(this.prevCondition) || !this.prevCondition)) {
  614. * this.prevCondition = true;
  615. * this.viewContainer.clear();
  616. * } else if (!newCondition && (isBlank(this.prevCondition) || this.prevCondition)) {
  617. * this.prevCondition = false;
  618. * this.viewContainer.create(this.templateRef);
  619. * }
  620. * }
  621. * }
  622. * ```
  623. *
  624. * We can then use this `unless` selector in a template:
  625. * ```
  626. * <ul>
  627. * <li *unless="expr"></li>
  628. * </ul>
  629. * ```
  630. *
  631. * Once the directive instantiates the child view, the shorthand notation for the template expands
  632. * and the result is:
  633. *
  634. * ```
  635. * <ul>
  636. * <template [unless]="exp">
  637. * <li></li>
  638. * </template>
  639. * <li></li>
  640. * </ul>
  641. * ```
  642. *
  643. * Note also that although the `<li></li>` template still exists inside the `<template></template>`,
  644. * the instantiated
  645. * view occurs on the second `<li></li>` which is a sibling to the `<template>` element.
  646. */
  647. class DirectiveMetadata extends InjectableMetadata {
  648. /**
  649. * The CSS selector that triggers the instantiation of a directive.
  650. *
  651. * Angular only allows directives to trigger on CSS selectors that do not cross element
  652. * boundaries.
  653. *
  654. * `selector` may be declared as one of the following:
  655. *
  656. * - `element-name`: select by element name.
  657. * - `.class`: select by class name.
  658. * - `[attribute]`: select by attribute name.
  659. * - `[attribute=value]`: select by attribute name and value.
  660. * - `:not(sub_selector)`: select only if the element does not match the `sub_selector`.
  661. * - `selector1, selector2`: select if either `selector1` or `selector2` matches.
  662. *
  663. *
  664. * ## Example
  665. *
  666. * Suppose we have a directive with an `input[type=text]` selector.
  667. *
  668. * And the following HTML:
  669. *
  670. * ```html
  671. * <form>
  672. * <input type="text">
  673. * <input type="radio">
  674. * <form>
  675. * ```
  676. *
  677. * The directive would only be instantiated on the `<input type="text">` element.
  678. */
  679. selector: string;
  680. /**
  681. * Enumerates the set of properties that accept data binding for a directive.
  682. *
  683. * The `properties` property defines a set of `directiveProperty` to `bindingProperty`
  684. * configuration:
  685. *
  686. * - `directiveProperty` specifies the component property where the value is written.
  687. * - `bindingProperty` specifies the DOM property where the value is read from.
  688. *
  689. * You can include a {@link PipeMetadata} when specifying a `bindingProperty` to allow for data
  690. * transformation and structural change detection of the value. These pipes will be evaluated in
  691. * the context of this component.
  692. *
  693. * ## Syntax
  694. *
  695. * There is no need to specify both `directiveProperty` and `bindingProperty` when they both have
  696. * the same value.
  697. *
  698. * ```
  699. * @Directive({
  700. * properties: [
  701. * 'propertyName', // shorthand notation for 'propertyName: propertyName'
  702. * 'directiveProperty1: bindingProperty1',
  703. * 'directiveProperty2: bindingProperty2 | pipe1 | ...',
  704. * ...
  705. * ]
  706. * }
  707. * ```
  708. *
  709. *
  710. * ## Basic Property Binding
  711. *
  712. * We can easily build a simple `Tooltip` directive that exposes a `tooltip` property, which can
  713. * be used in templates with standard Angular syntax. For example:
  714. *
  715. * ```
  716. * @Directive({
  717. * selector: '[tooltip]',
  718. * properties: [
  719. * 'text: tooltip'
  720. * ]
  721. * })
  722. * class Tooltip {
  723. * set text(value: string) {
  724. * // This will get called every time with the new value when the 'tooltip' property changes
  725. * }
  726. * }
  727. * ```
  728. *
  729. * We can then bind to the `tooltip' property as either an expression (`someExpression`) or as a
  730. * string literal, as shown in the HTML template below:
  731. *
  732. * ```html
  733. * <div [tooltip]="someExpression">...</div>
  734. * <div tooltip="Some Text">...</div>
  735. * ```
  736. *
  737. * Whenever the `someExpression` expression changes, the `properties` declaration instructs
  738. * Angular to update the `Tooltip`'s `text` property.
  739. *
  740. * ### Bindings With Pipes
  741. *
  742. * You can use pipes in bindings, as follows:
  743. *
  744. * ```html
  745. * <div [class-set]="someExpression | somePipe">
  746. * ```
  747. */
  748. properties: string[];
  749. /**
  750. * Enumerates the set of emitted events.
  751. *
  752. * ## Syntax
  753. *
  754. * ```
  755. * @Component({
  756. * events: ['statusChange']
  757. * })
  758. * class TaskComponent {
  759. * statusChange: EventEmitter;
  760. *
  761. * constructor() {
  762. * this.statusChange = new EventEmitter();
  763. * }
  764. *
  765. * onComplete() {
  766. * this.statusChange.next('completed');
  767. * }
  768. * }
  769. * ```
  770. *
  771. * Use `propertyName: eventName` when the event emitter property name is different from the name
  772. * of the emitted event:
  773. *
  774. * ```
  775. * @Component({
  776. * events: ['status: statusChange']
  777. * })
  778. * class TaskComponent {
  779. * status: EventEmitter;
  780. *
  781. * constructor() {
  782. * this.status = new EventEmitter();
  783. * }
  784. *
  785. * onComplete() {
  786. * this.status.next('completed');
  787. * }
  788. * }
  789. * ```
  790. */
  791. events: string[];
  792. /**
  793. * Specifiy the events, actions, properties and attributes related to the host element.
  794. *
  795. * ## Events
  796. *
  797. * Specifies which DOM hostListeners a directive listens to via a set of `(event)` to `method`
  798. * key-value pairs:
  799. *
  800. * - `event1`: the DOM event that the directive listens to.
  801. * - `statement`: the statement to execute when the event occurs.
  802. * If the evalutation of the statement returns `false`, then `preventDefault`is applied on the DOM
  803. * event.
  804. *
  805. * To listen to global events, a target must be added to the event name.
  806. * The target can be `window`, `document` or `body`.
  807. *
  808. * When writing a directive event binding, you can also refer to the following local variables:
  809. * - `$event`: Current event object which triggered the event.
  810. * - `$target`: The source of the event. This will be either a DOM element or an Angular
  811. * directive. (will be implemented in later release)
  812. *
  813. * ## Syntax
  814. *
  815. * ```
  816. * @Directive({
  817. * host: {
  818. * '(event1)': 'onMethod1(arguments)',
  819. * '(target:event2)': 'onMethod2(arguments)',
  820. * ...
  821. * }
  822. * }
  823. * ```
  824. *
  825. * ## Basic Event Binding:
  826. *
  827. * Suppose you want to write a directive that reacts to `change` events in the DOM and on
  828. * `resize` events in window.
  829. * You would define the event binding as follows:
  830. *
  831. * ```
  832. * @Directive({
  833. * selector: 'input',
  834. * host: {
  835. * '(change)': 'onChange($event)',
  836. * '(window:resize)': 'onResize($event)'
  837. * }
  838. * })
  839. * class InputDirective {
  840. * onChange(event:Event) {
  841. * // invoked when the input element fires the 'change' event
  842. * }
  843. * onResize(event:Event) {
  844. * // invoked when the window fires the 'resize' event
  845. * }
  846. * }
  847. * ```
  848. *
  849. * ## Properties
  850. *
  851. * Specifies which DOM properties a directives updates.
  852. *
  853. * ## Syntax
  854. *
  855. * ```
  856. * @Directive({
  857. * selector: 'input',
  858. * host: {
  859. * '[prop]': 'expression'
  860. * }
  861. * })
  862. * class InputDirective {
  863. * value:string;
  864. * }
  865. * ```
  866. *
  867. * In this example the prop property of the host element is updated with the expression value
  868. * every time it changes.
  869. *
  870. * ## Attributes
  871. *
  872. * Specifies static attributes that should be propagated to a host element. Attributes specified
  873. * in `hostAttributes` are propagated only if a given attribute is not present on a host element.
  874. *
  875. * ## Syntax
  876. *
  877. * ```
  878. * @Directive({
  879. * selector: '[my-button]',
  880. * host: {
  881. * 'role': 'button'
  882. * }
  883. * })
  884. * class MyButton {
  885. * }
  886. * ```
  887. *
  888. * In this example using `my-button` directive (ex.: `<div my-button></div>`) on a host element
  889. * (here: `<div>` ) will ensure that this element will get the "button" role.
  890. */
  891. host: StringMap<string, string>;
  892. /**
  893. * Specifies which lifecycle should be notified to the directive.
  894. *
  895. * See {@link LifecycleEvent} for details.
  896. */
  897. lifecycle: LifecycleEvent[];
  898. /**
  899. * If set to false the compiler does not compile the children of this directive.
  900. */
  901. compileChildren: boolean;
  902. /**
  903. * Defines the set of injectable objects that are visible to a Directive and its light dom
  904. * children.
  905. *
  906. * ## Simple Example
  907. *
  908. * Here is an example of a class that can be injected:
  909. *
  910. * ```
  911. * class Greeter {
  912. * greet(name:string) {
  913. * return 'Hello ' + name + '!';
  914. * }
  915. * }
  916. *
  917. * @Directive({
  918. * selector: 'greet',
  919. * bindings: [
  920. * Greeter
  921. * ]
  922. * })
  923. * class HelloWorld {
  924. * greeter:Greeter;
  925. *
  926. * constructor(greeter:Greeter) {
  927. * this.greeter = greeter;
  928. * }
  929. * }
  930. * ```
  931. */
  932. bindings: any[];
  933. /**
  934. * Defines the name that can be used in the template to assign this directive to a variable.
  935. *
  936. * ## Simple Example
  937. *
  938. * ```
  939. * @Directive({
  940. * selector: 'child-dir',
  941. * exportAs: 'child'
  942. * })
  943. * class ChildDir {
  944. * }
  945. *
  946. * @Component({
  947. * selector: 'main',
  948. * })
  949. * @View({
  950. * template: `<child-dir #c="child"></child-dir>`,
  951. * directives: [ChildDir]
  952. * })
  953. * class MainComponent {
  954. * }
  955. *
  956. * ```
  957. */
  958. exportAs: string;
  959. }
  960. /**
  961. * Declare reusable pipe function.
  962. *
  963. * ## Example
  964. *
  965. * ```
  966. * @Pipe({
  967. * name: 'lowercase'
  968. * })
  969. * class Lowercase {
  970. * transform(v, args) { return v.toLowerCase(); }
  971. * }
  972. * ```
  973. */
  974. class PipeMetadata extends InjectableMetadata {
  975. name: string;
  976. }
  977. /**
  978. * Lifecycle events are guaranteed to be called in the following order:
  979. * - `OnChanges` (if any bindings have changed),
  980. * - `OnInit` (after the first check only),
  981. * - `DoCheck`,
  982. * - `AfterContentChecked`
  983. * - `AfterContentChecked`
  984. * - `OnDestroy` (at the very end before destruction)
  985. */
  986. enum LifecycleEvent {
  987. /**
  988. * Notify a directive when it has been checked the first time.
  989. *
  990. * This method is called right after the directive's bindings have been checked,
  991. * and before any of its children's bindings have been checked.
  992. *
  993. * It is invoked only once.
  994. *
  995. * ## Example
  996. *
  997. * ```
  998. * @Directive({
  999. * selector: '[class-set]',
  1000. * lifecycle: [LifecycleEvent.OnInit]
  1001. * })
  1002. * class ClassSet {
  1003. * onInit() {
  1004. * }
  1005. * }
  1006. * ```
  1007. */
  1008. OnInit,
  1009. /**
  1010. * Notify a directive whenever a {@link ViewMetadata} that contains it is destroyed.
  1011. *
  1012. * ## Example
  1013. *
  1014. * ```
  1015. * @Directive({
  1016. * ...,
  1017. * lifecycle: [LifecycleEvent.OnDestroy]
  1018. * })
  1019. * class ClassSet {
  1020. * onDestroy() {
  1021. * // invoked to notify directive of the containing view destruction.
  1022. * }
  1023. * }
  1024. * ```
  1025. */
  1026. OnDestroy,
  1027. /**
  1028. * Notify a directive when any of its bindings have changed.
  1029. *
  1030. * This method is called right after the directive's bindings have been checked,
  1031. * and before any of its children's bindings have been checked.
  1032. *
  1033. * It is invoked only if at least one of the directive's bindings has changed.
  1034. *
  1035. * ## Example:
  1036. *
  1037. * ```
  1038. * @Directive({
  1039. * selector: '[class-set]',
  1040. * properties: [
  1041. * 'propA',
  1042. * 'propB'
  1043. * ],
  1044. * lifecycle: [LifecycleEvent.OnChanges]
  1045. * })
  1046. * class ClassSet {
  1047. * propA;
  1048. * propB;
  1049. * onChanges(changes:{[idx: string, PropertyUpdate]}) {
  1050. * // This will get called after any of the properties have been updated.
  1051. * if (changes['propA']) {
  1052. * // if propA was updated
  1053. * }
  1054. * if (changes['propA']) {
  1055. * // if propB was updated
  1056. * }
  1057. * }
  1058. * }
  1059. * ```
  1060. */
  1061. OnChanges,
  1062. /**
  1063. * Notify a directive when it has been checked.
  1064. *
  1065. * This method is called right after the directive's bindings have been checked,
  1066. * and before any of its children's bindings have been checked.
  1067. *
  1068. * It is invoked every time even when none of the directive's bindings has changed.
  1069. *
  1070. * ## Example
  1071. *
  1072. * ```
  1073. * @Directive({
  1074. * selector: '[class-set]',
  1075. * lifecycle: [LifecycleEvent.DoCheck]
  1076. * })
  1077. * class ClassSet {
  1078. * doCheck() {
  1079. * }
  1080. * }
  1081. * ```
  1082. */
  1083. DoCheck,
  1084. /**
  1085. * Notify a directive when the bindings of all its content children have been checked the first
  1086. * time (whether they
  1087. * have changed or not).
  1088. *
  1089. * ## Example
  1090. *
  1091. * ```
  1092. * @Directive({
  1093. * selector: '[class-set]',
  1094. * lifecycle: [LifecycleEvent.AfterContentInit]
  1095. * })
  1096. * class ClassSet {
  1097. *
  1098. * afterContentInit() {
  1099. * }
  1100. *
  1101. * }
  1102. * ```
  1103. */
  1104. AfterContentInit,
  1105. /**
  1106. * Notify a directive when the bindings of all its content children have been checked (whether
  1107. * they
  1108. * have changed or not).
  1109. *
  1110. * ## Example
  1111. *
  1112. * ```
  1113. * @Directive({
  1114. * selector: '[class-set]',
  1115. * lifecycle: [LifecycleEvent.AfterContentChecked]
  1116. * })
  1117. * class ClassSet {
  1118. *
  1119. * afterContentChecked() {
  1120. * }
  1121. *
  1122. * }
  1123. * ```
  1124. */
  1125. AfterContentChecked,
  1126. /**
  1127. * Notify a directive when the bindings of all its view children have been checked the first time
  1128. * (whether they
  1129. * have changed or not).
  1130. *
  1131. * ## Example
  1132. *
  1133. * ```
  1134. * @Directive({
  1135. * selector: '[class-set]',
  1136. * lifecycle: [LifecycleEvent.AfterViewInit]
  1137. * })
  1138. * class ClassSet {
  1139. *
  1140. * afterViewInit() {
  1141. * }
  1142. *
  1143. * }
  1144. * ```
  1145. */
  1146. AfterViewInit,
  1147. /**
  1148. * Notify a directive when the bindings of all its view children have been checked (whether they
  1149. * have changed or not).
  1150. *
  1151. * ## Example
  1152. *
  1153. * ```
  1154. * @Directive({
  1155. * selector: '[class-set]',
  1156. * lifecycle: [LifecycleEvent.AfterViewChecked]
  1157. * })
  1158. * class ClassSet {
  1159. *
  1160. * afterViewChecked() {
  1161. * }
  1162. *
  1163. * }
  1164. * ```
  1165. */
  1166. AfterViewChecked
  1167. }
  1168. /**
  1169. * Declares the available HTML templates for an application.
  1170. *
  1171. * Each angular component requires a single `@Component` and at least one `@View` annotation. The
  1172. * `@View` annotation specifies the HTML template to use, and lists the directives that are active
  1173. * within the template.
  1174. *
  1175. * When a component is instantiated, the template is loaded into the component's shadow root, and
  1176. * the expressions and statements in the template are evaluated against the component.
  1177. *
  1178. * For details on the `@Component` annotation, see {@link ComponentMetadata}.
  1179. *
  1180. * ## Example
  1181. *
  1182. * ```
  1183. * @Component({
  1184. * selector: 'greet'
  1185. * })
  1186. * @View({
  1187. * template: 'Hello {{name}}!',
  1188. * directives: [GreetUser, Bold]
  1189. * })
  1190. * class Greet {
  1191. * name: string;
  1192. *
  1193. * constructor() {
  1194. * this.name = 'World';
  1195. * }
  1196. * }
  1197. * ```
  1198. */
  1199. class ViewMetadata {
  1200. /**
  1201. * Specifies a template URL for an angular component.
  1202. *
  1203. * NOTE: either `templateUrl` or `template` should be used, but not both.
  1204. */
  1205. templateUrl: string;
  1206. /**
  1207. * Specifies an inline template for an angular component.
  1208. *
  1209. * NOTE: either `templateUrl` or `template` should be used, but not both.
  1210. */
  1211. template: string;
  1212. /**
  1213. * Specifies stylesheet URLs for an angular component.
  1214. */
  1215. styleUrls: string[];
  1216. /**
  1217. * Specifies an inline stylesheet for an angular component.
  1218. */
  1219. styles: string[];
  1220. /**
  1221. * Specifies a list of directives that can be used within a template.
  1222. *
  1223. * Directives must be listed explicitly to provide proper component encapsulation.
  1224. *
  1225. * ## Example
  1226. *
  1227. * ```javascript
  1228. * @Component({
  1229. * selector: 'my-component'
  1230. * })
  1231. * @View({
  1232. * directives: [For]
  1233. * template: '
  1234. * <ul>
  1235. * <li *ng-for="#item of items">{{item}}</li>
  1236. * </ul>'
  1237. * })
  1238. * class MyComponent {
  1239. * }
  1240. * ```
  1241. */
  1242. directives: Array<Type | any | any[]>;
  1243. pipes: Array<Type | any | any[]>;
  1244. /**
  1245. * Specify how the template and the styles should be encapsulated.
  1246. * The default is {@link ViewEncapsulation#Emulated `ViewEncapsulation.Emulated`} if the view
  1247. * has styles,
  1248. * otherwise {@link ViewEncapsulation#None `ViewEncapsulation.None`}.
  1249. */
  1250. encapsulation: ViewEncapsulation;
  1251. }
  1252. /**
  1253. * How the template and styles of a view should be encapsulated.
  1254. */
  1255. enum ViewEncapsulation {
  1256. /**
  1257. * Emulate scoping of styles by preprocessing the style rules
  1258. * and adding additional attributes to elements. This is the default.
  1259. */
  1260. Emulated,
  1261. /**
  1262. * Uses the native mechanism of the renderer. For the DOM this means creating a ShadowRoot.
  1263. */
  1264. Native,
  1265. /**
  1266. * Don't scope the template nor the styles.
  1267. */
  1268. None
  1269. }
  1270. /**
  1271. * Specifies that a {@link QueryList} should be injected.
  1272. *
  1273. * See {@link QueryList} for usage and example.
  1274. */
  1275. class QueryMetadata extends DependencyMetadata {
  1276. descendants: boolean;
  1277. isViewQuery: any;
  1278. selector: any;
  1279. isVarBindingQuery: boolean;
  1280. varBindings: string[];
  1281. toString(): string;
  1282. }
  1283. /**
  1284. * Specifies that a constant attribute value should be injected.
  1285. *
  1286. * The directive can inject constant string literals of host element attributes.
  1287. *
  1288. * ## Example
  1289. *
  1290. * Suppose we have an `<input>` element and want to know its `type`.
  1291. *
  1292. * ```html
  1293. * <input type="text">
  1294. * ```
  1295. *
  1296. * A decorator can inject string literal `text` like so:
  1297. *
  1298. * ```javascript
  1299. * @Directive({
  1300. * selector: `input'
  1301. * })
  1302. * class InputDirective {
  1303. * constructor(@Attribute('type') type) {
  1304. * // type would be `text` in this example
  1305. * }
  1306. * }
  1307. * ```
  1308. */
  1309. class AttributeMetadata extends DependencyMetadata {
  1310. attributeName: string;
  1311. token: any;
  1312. toString(): string;
  1313. }
  1314. /**
  1315. * {@link AttributeMetadata} factory function.
  1316. */
  1317. var Attribute : AttributeFactory ;
  1318. /**
  1319. * {@link AttributeMetadata} factory for creating annotations, decorators or DSL.
  1320. *
  1321. * ## Example as TypeScript Decorator
  1322. *
  1323. * ```
  1324. * import {Attribute, Component, View} from "angular2/angular2";
  1325. *
  1326. * @Component({...})
  1327. * @View({...})
  1328. * class MyComponent {
  1329. * constructor(@Attribute('title') title: string) {
  1330. * ...
  1331. * }
  1332. * }
  1333. * ```
  1334. *
  1335. * ## Example as ES5 DSL
  1336. *
  1337. * ```
  1338. * var MyComponent = ng
  1339. * .Component({...})
  1340. * .View({...})
  1341. * .Class({
  1342. * constructor: [new ng.Attribute('title'), function(title) {
  1343. * ...
  1344. * }]
  1345. * })
  1346. * ```
  1347. *
  1348. * ## Example as ES5 annotation
  1349. *
  1350. * ```
  1351. * var MyComponent = function(title) {
  1352. * ...
  1353. * };
  1354. *
  1355. * MyComponent.annotations = [
  1356. * new ng.Component({...}),
  1357. * new ng.View({...})
  1358. * ]
  1359. * MyComponent.parameters = [
  1360. * [new ng.Attribute('title')]
  1361. * ]
  1362. * ```
  1363. */
  1364. interface AttributeFactory {
  1365. new(name: string): AttributeMetadata;
  1366. (name: string): TypeDecorator;
  1367. }
  1368. /**
  1369. * {@link ComponentMetadata} factory function.
  1370. */
  1371. var Component : ComponentFactory ;
  1372. /**
  1373. * Interface for the {@link ComponentMetadata} decorator function.
  1374. *
  1375. * See {@link ComponentFactory}.
  1376. */
  1377. interface ComponentDecorator extends TypeDecorator {
  1378. /**
  1379. * Chain {@link ViewMetadata} annotation.
  1380. */
  1381. View(obj: {
  1382. templateUrl?: string,
  1383. template?: string,
  1384. directives?: Array<Type | any | any[]>,
  1385. pipes?: Array<Type | any | any[]>,
  1386. renderer?: string,
  1387. styles?: string[],
  1388. styleUrls?: string[],
  1389. }): ViewDecorator;
  1390. }
  1391. /**
  1392. * {@link ComponentAnnotation} factory for creating annotations, decorators or DSL.
  1393. *
  1394. * ## Example as TypeScript Decorator
  1395. *
  1396. * ```
  1397. * import {Component, View} from "angular2/angular2";
  1398. *
  1399. * @Component({...})
  1400. * @View({...})
  1401. * class MyComponent {
  1402. * constructor() {
  1403. * ...
  1404. * }
  1405. * }
  1406. * ```
  1407. *
  1408. * ## Example as ES5 DSL
  1409. *
  1410. * ```
  1411. * var MyComponent = ng
  1412. * .Component({...})
  1413. * .View({...})
  1414. * .Class({
  1415. * constructor: function() {
  1416. * ...
  1417. * }
  1418. * })
  1419. * ```
  1420. *
  1421. * ## Example as ES5 annotation
  1422. *
  1423. * ```
  1424. * var MyComponent = function() {
  1425. * ...
  1426. * };
  1427. *
  1428. * MyComponent.annotations = [
  1429. * new ng.Component({...}),
  1430. * new ng.View({...})
  1431. * ]
  1432. * ```
  1433. */
  1434. interface ComponentFactory {
  1435. new(obj: {
  1436. selector?: string,
  1437. properties?: string[],
  1438. events?: string[],
  1439. host?: StringMap<string, string>,
  1440. lifecycle?: LifecycleEvent[],
  1441. bindings?: any[],
  1442. exportAs?: string,
  1443. compileChildren?: boolean,
  1444. viewBindings?: any[],
  1445. changeDetection?: ChangeDetectionStrategy,
  1446. }): ComponentMetadata;
  1447. (obj: {
  1448. selector?: string,
  1449. properties?: string[],
  1450. events?: string[],
  1451. host?: StringMap<string, string>,
  1452. lifecycle?: LifecycleEvent[],
  1453. bindings?: any[],
  1454. exportAs?: string,
  1455. compileChildren?: boolean,
  1456. viewBindings?: any[],
  1457. changeDetection?: ChangeDetectionStrategy,
  1458. }): ComponentDecorator;
  1459. }
  1460. /**
  1461. * {@link DirectiveMetadata} factory function.
  1462. */
  1463. var Directive : DirectiveFactory ;
  1464. /**
  1465. * Interface for the {@link DirectiveMetadata} decorator function.
  1466. *
  1467. * See {@link DirectiveFactory}.
  1468. */
  1469. interface DirectiveDecorator extends TypeDecorator {
  1470. }
  1471. /**
  1472. * {@link DirectiveMetadata} factory for creating annotations, decorators or DSL.
  1473. *
  1474. * ## Example as TypeScript Decorator
  1475. *
  1476. * ```
  1477. * import {Directive} from "angular2/angular2";
  1478. *
  1479. * @Directive({...})
  1480. * class MyDirective {
  1481. * constructor() {
  1482. * ...
  1483. * }
  1484. * }
  1485. * ```
  1486. *
  1487. * ## Example as ES5 DSL
  1488. *
  1489. * ```
  1490. * var MyDirective = ng
  1491. * .Directive({...})
  1492. * .Class({
  1493. * constructor: function() {
  1494. * ...
  1495. * }
  1496. * })
  1497. * ```
  1498. *
  1499. * ## Example as ES5 annotation
  1500. *
  1501. * ```
  1502. * var MyDirective = function() {
  1503. * ...
  1504. * };
  1505. *
  1506. * MyDirective.annotations = [
  1507. * new ng.Directive({...})
  1508. * ]
  1509. * ```
  1510. */
  1511. interface DirectiveFactory {
  1512. new(obj: {
  1513. selector?: string, properties?: string[], events?: string[], host?: StringMap<string, string>,
  1514. lifecycle?: LifecycleEvent[], bindings?: any[], exportAs?: string,
  1515. compileChildren?: boolean;
  1516. }): DirectiveMetadata;
  1517. (obj: {
  1518. selector?: string, properties?: string[], events?: string[], host?: StringMap<string, string>,
  1519. lifecycle?: LifecycleEvent[], bindings?: any[], exportAs?: string,
  1520. compileChildren?: boolean;
  1521. }): DirectiveDecorator;
  1522. }
  1523. /**
  1524. * {@link ViewMetadata} factory function.
  1525. */
  1526. var View : ViewFactory ;
  1527. /**
  1528. * Interface for the {@link ViewMetadata} decorator function.
  1529. *
  1530. * See {@link ViewFactory}.
  1531. */
  1532. interface ViewDecorator extends TypeDecorator {
  1533. /**
  1534. * Chain {@link ViewMetadata} annotation.
  1535. */
  1536. View(obj: {
  1537. templateUrl?: string,
  1538. template?: string,
  1539. directives?: Array<Type | any | any[]>,
  1540. pipes?: Array<Type | any | any[]>,
  1541. renderer?: string,
  1542. styles?: string[],
  1543. styleUrls?: string[],
  1544. }): ViewDecorator;
  1545. }
  1546. /**
  1547. * {@link ViewAnnotation} factory for creating annotations, decorators or DSL.
  1548. *
  1549. * ## Example as TypeScript Decorator
  1550. *
  1551. * ```
  1552. * import {Component, View} from "angular2/angular2";
  1553. *
  1554. * @Component({...})
  1555. * @View({...})
  1556. * class MyComponent {
  1557. * constructor() {
  1558. * ...
  1559. * }
  1560. * }
  1561. * ```
  1562. *
  1563. * ## Example as ES5 DSL
  1564. *
  1565. * ```
  1566. * var MyComponent = ng
  1567. * .Component({...})
  1568. * .View({...})
  1569. * .Class({
  1570. * constructor: function() {
  1571. * ...
  1572. * }
  1573. * })
  1574. * ```
  1575. *
  1576. * ## Example as ES5 annotation
  1577. *
  1578. * ```
  1579. * var MyComponent = function() {
  1580. * ...
  1581. * };
  1582. *
  1583. * MyComponent.annotations = [
  1584. * new ng.Component({...}),
  1585. * new ng.View({...})
  1586. * ]
  1587. * ```
  1588. */
  1589. interface ViewFactory {
  1590. new(obj: {
  1591. templateUrl?: string,
  1592. template?: string,
  1593. directives?: Array<Type | any | any[]>,
  1594. encapsulation?: ViewEncapsulation,
  1595. styles?: string[],
  1596. styleUrls?: string[],
  1597. }): ViewMetadata;
  1598. (obj: {
  1599. templateUrl?: string,
  1600. template?: string,
  1601. directives?: Array<Type | any | any[]>,
  1602. encapsulation?: ViewEncapsulation,
  1603. styles?: string[],
  1604. styleUrls?: string[],
  1605. }): ViewDecorator;
  1606. }
  1607. /**
  1608. * {@link QueryMetadata} factory function.
  1609. */
  1610. var Query : QueryFactory ;
  1611. /**
  1612. * {@link QueryMetadata} factory for creating annotations, decorators or DSL.
  1613. *
  1614. * ## Example as TypeScript Decorator
  1615. *
  1616. * ```
  1617. * import {Query, QueryList, Component, View} from "angular2/angular2";
  1618. *
  1619. * @Component({...})
  1620. * @View({...})
  1621. * class MyComponent {
  1622. * constructor(@Query(SomeType) queryList: QueryList) {
  1623. * ...
  1624. * }
  1625. * }
  1626. * ```
  1627. *
  1628. * ## Example as ES5 DSL
  1629. *
  1630. * ```
  1631. * var MyComponent = ng
  1632. * .Component({...})
  1633. * .View({...})
  1634. * .Class({
  1635. * constructor: [new ng.Query(SomeType), function(queryList) {
  1636. * ...
  1637. * }]
  1638. * })
  1639. * ```
  1640. *
  1641. * ## Example as ES5 annotation
  1642. *
  1643. * ```
  1644. * var MyComponent = function(queryList) {
  1645. * ...
  1646. * };
  1647. *
  1648. * MyComponent.annotations = [
  1649. * new ng.Component({...}),
  1650. * new ng.View({...})
  1651. * ]
  1652. * MyComponent.parameters = [
  1653. * [new ng.Query(SomeType)]
  1654. * ]
  1655. * ```
  1656. */
  1657. interface QueryFactory {
  1658. new(selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata;
  1659. (selector: Type | string, {descendants}?: {descendants?: boolean}): ParameterDecorator;
  1660. }
  1661. /**
  1662. * {@link di/ViewQueryMetadata} factory function.
  1663. */
  1664. var ViewQuery : QueryFactory ;
  1665. /**
  1666. * {@link PipeMetadata} factory function.
  1667. */
  1668. var Pipe : PipeFactory ;
  1669. /**
  1670. * {@link PipeMetadata} factory for creating decorators.
  1671. *
  1672. * ## Example as TypeScript Decorator
  1673. *
  1674. * ```
  1675. * import {Pipe} from "angular2/angular2";
  1676. *
  1677. * @Pipe({...})
  1678. * class MyPipe {
  1679. * constructor() {
  1680. * ...
  1681. * }
  1682. *
  1683. * transform(v, args) {}
  1684. * }
  1685. * ```
  1686. */
  1687. interface PipeFactory {
  1688. new(obj: {
  1689. name: string,
  1690. }): any;
  1691. (obj: {name: string}): any;
  1692. }
  1693. /**
  1694. * Defines lifecycle method
  1695. * {@link metadata/LifeCycleEvent#AfterContentInit `LifeCycleEvent.afterContentInit`}
  1696. * called when the bindings of all its content children have been checked the first time.
  1697. */
  1698. interface AfterContentInit {
  1699. afterContentInit(): void;
  1700. }
  1701. /**
  1702. * Defines lifecycle method
  1703. * {@link metadata/LifeCycleEvent#AfterContentChecked `LifeCycleEvent.afterContentChecked`}
  1704. * called when the bindings of all its content children have been checked.
  1705. */
  1706. interface AfterContentChecked {
  1707. afterContentChecked(): void;
  1708. }
  1709. /**
  1710. * Defines lifecycle method
  1711. * {@link metadata/LifeCycleEvent#AfterViewInit `LifeCycleEvent.afterViewInit`}
  1712. * called when the bindings of all its view children have been checked the first time.
  1713. */
  1714. interface AfterViewInit {
  1715. afterViewInit(): void;
  1716. }
  1717. /**
  1718. * Defines lifecycle method
  1719. * {@link metadata/LifeCycleEvent#AfterViewChecked `LifeCycleEvent.afterViewChecked`}
  1720. * called when the bindings of all its view children have been checked.
  1721. */
  1722. interface AfterViewChecked {
  1723. afterViewChecked(): void;
  1724. }
  1725. /**
  1726. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnChanges `LifeCycleEvent.OnChanges`}
  1727. * called after all of component's bound properties are updated.
  1728. */
  1729. interface OnChanges {
  1730. onChanges(changes: StringMap<string, any>): void;
  1731. }
  1732. /**
  1733. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnDestroy `LifeCycleEvent.OnDestroy`}
  1734. * called when a directive is being destroyed.
  1735. */
  1736. interface OnDestroy {
  1737. onDestroy(): void;
  1738. }
  1739. /**
  1740. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnInit `LifeCycleEvent.OnInit`}
  1741. * called when a directive is being checked the first time.
  1742. */
  1743. interface OnInit {
  1744. onInit(): void;
  1745. }
  1746. /**
  1747. * Defines lifecycle method {@link metadata/LifeCycleEvent#DoCheck `LifeCycleEvent.DoCheck`}
  1748. * called when a directive is being checked.
  1749. */
  1750. interface DoCheck {
  1751. doCheck(): boolean;
  1752. }
  1753. /**
  1754. * Provides a way for expressing ES6 classes with parameter annotations in ES5.
  1755. *
  1756. * ## Basic Example
  1757. *
  1758. * ```
  1759. * var Greeter = ng.Class({
  1760. * constructor: function(name) {
  1761. * this.name = name;
  1762. * },
  1763. *
  1764. * greet: function() {
  1765. * alert('Hello ' + this.name + '!');
  1766. * }
  1767. * });
  1768. * ```
  1769. *
  1770. * is equivalent to ES6:
  1771. *
  1772. * ```
  1773. * class Greeter {
  1774. * constructor(name) {
  1775. * this.name = name;
  1776. * }
  1777. *
  1778. * greet() {
  1779. * alert('Hello ' + this.name + '!');
  1780. * }
  1781. * }
  1782. * ```
  1783. *
  1784. * or equivalent to ES5:
  1785. *
  1786. * ```
  1787. * var Greeter = function (name) {
  1788. * this.name = name;
  1789. * }
  1790. *
  1791. * Greeter.prototype.greet = function () {
  1792. * alert('Hello ' + this.name + '!');
  1793. * }
  1794. * ```
  1795. *
  1796. * ## Example with parameter annotations
  1797. *
  1798. * ```
  1799. * var MyService = neg.Class({
  1800. * constructor: [String, [new Query(), QueryList], function(name, queryList) {
  1801. * ...
  1802. * }];
  1803. * });
  1804. * ```
  1805. *
  1806. * is equivalent to ES6:
  1807. *
  1808. * ```
  1809. * class MyService {
  1810. * constructor(name: string, @Query() queryList: QueryList) {
  1811. * ...
  1812. * }
  1813. * }
  1814. * ```
  1815. *
  1816. * ## Example with inheritance
  1817. *
  1818. * ```
  1819. * var Shape = ng.Class({
  1820. * constructor: (color) {
  1821. * this.color = color;
  1822. * }
  1823. * });
  1824. *
  1825. * var Square = ng.Class({
  1826. * extends: Shape,
  1827. * constructor: function(color, size) {
  1828. * Shape.call(this, color);
  1829. * this.size = size;
  1830. * }
  1831. * });
  1832. * ```
  1833. */
  1834. function Class(clsDef: ClassDefinition) : Type ;
  1835. /**
  1836. * Declares the interface to be used with {@link Class}.
  1837. */
  1838. interface ClassDefinition {
  1839. /**
  1840. * Optional argument for specifying the superclass.
  1841. */
  1842. extends?: Type;
  1843. /**
  1844. * Required constructor function for a class.
  1845. *
  1846. * The function may be optionally wrapped in an `Array`, in which case additional parameter
  1847. * annotations may be specified.
  1848. * The number of arguments and the number of parameter annotations must match.
  1849. *
  1850. * See {@link Class} for example of usage.
  1851. */
  1852. constructor: (Function | any[]);
  1853. }
  1854. /**
  1855. * An interface implemented by all Angular type decorators, which allows them to be used as ES7
  1856. * decorators as well as
  1857. * Angular DSL syntax.
  1858. *
  1859. * DSL syntax:
  1860. *
  1861. * ```
  1862. * var MyClass = ng
  1863. * .Component({...})
  1864. * .View({...})
  1865. * .Class({...});
  1866. * ```
  1867. *
  1868. * ES7 syntax:
  1869. *
  1870. * ```
  1871. * @ng.Component({...})
  1872. * @ng.View({...})
  1873. * class MyClass {...}
  1874. * ```
  1875. */
  1876. interface TypeDecorator {
  1877. /**
  1878. * Invoke as ES7 decorator.
  1879. */
  1880. <T extends Type>(type: T): T;
  1881. /**
  1882. * Storage for the accumulated annotations so far used by the DSL syntax.
  1883. *
  1884. * Used by {@link Class} to annotate the generated class.
  1885. */
  1886. annotations: any[];
  1887. /**
  1888. * Generate a class from the definition and annotate it with {@link TypeDecorator#annotations}.
  1889. */
  1890. Class(obj: ClassDefinition): Type;
  1891. }
  1892. enum ChangeDetectionStrategy {
  1893. /**
  1894. * `CheckedOnce` means that after calling detectChanges the mode of the change detector
  1895. * will become `Checked`.
  1896. */
  1897. CheckOnce,
  1898. /**
  1899. * `Checked` means that the change detector should be skipped until its mode changes to
  1900. * `CheckOnce`.
  1901. */
  1902. Checked,
  1903. /**
  1904. * `CheckAlways` means that after calling detectChanges the mode of the change detector
  1905. * will remain `CheckAlways`.
  1906. */
  1907. CheckAlways,
  1908. /**
  1909. * `Detached` means that the change detector sub tree is not a part of the main tree and
  1910. * should be skipped.
  1911. */
  1912. Detached,
  1913. /**
  1914. * `OnPush` means that the change detector's mode will be set to `CheckOnce` during hydration.
  1915. */
  1916. OnPush,
  1917. /**
  1918. * `Default` means that the change detector's mode will be set to `CheckAlways` during hydration.
  1919. */
  1920. Default,
  1921. /**
  1922. * This is an experimental feature. Works only in Dart.
  1923. */
  1924. OnPushObserve
  1925. }
  1926. /**
  1927. * An error thrown if application changes model breaking the top-down data flow.
  1928. *
  1929. * Angular expects that the data flows from top (root) component to child (leaf) components.
  1930. * This is known as directed acyclic graph. This allows Angular to only execute change detection
  1931. * once and prevents loops in change detection data flow.
  1932. *
  1933. * This exception is only thrown in dev mode.
  1934. */
  1935. class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
  1936. }
  1937. /**
  1938. * Thrown when an expression evaluation raises an exception.
  1939. *
  1940. * This error wraps the original exception, this is done to attach expression location information.
  1941. */
  1942. class ChangeDetectionError extends BaseException {
  1943. /**
  1944. * Location of the expression.
  1945. */
  1946. location: string;
  1947. }
  1948. interface ChangeDetector {
  1949. parent: ChangeDetector;
  1950. mode: ChangeDetectionStrategy;
  1951. ref: ChangeDetectorRef;
  1952. addChild(cd: ChangeDetector): void;
  1953. addShadowDomChild(cd: ChangeDetector): void;
  1954. removeChild(cd: ChangeDetector): void;
  1955. removeShadowDomChild(cd: ChangeDetector): void;
  1956. remove(): void;
  1957. hydrate(context: any, locals: Locals, directives: any, pipes: any): void;
  1958. dehydrate(): void;
  1959. markPathToRootAsCheckOnce(): void;
  1960. handleEvent(eventName: string, elIndex: number, locals: Locals): void;
  1961. detectChanges(): void;
  1962. checkNoChanges(): void;
  1963. }
  1964. class Locals {
  1965. parent: Locals;
  1966. current: Map<any, any>;
  1967. contains(name: string): boolean;
  1968. get(name: string): any;
  1969. set(name: string, value: any): void;
  1970. clearValues(): void;
  1971. }
  1972. /**
  1973. * Controls change detection.
  1974. *
  1975. * {@link ChangeDetectorRef} allows requesting checks for detectors that rely on observables. It
  1976. * also allows detaching and attaching change detector subtrees.
  1977. */
  1978. interface ChangeDetectorRef {
  1979. /**
  1980. * Request to check all OnPush ancestors.
  1981. */
  1982. markForCheck(): void;
  1983. /**
  1984. * Detaches the change detector from the change detector tree.
  1985. *
  1986. * The detached change detector will not be checked until it is reattached.
  1987. */
  1988. detach(): void;
  1989. /**
  1990. * Reattach the change detector to the change detector tree.
  1991. *
  1992. * This also requests a check of this change detector. This reattached change detector will be
  1993. * checked during the next change detection run.
  1994. */
  1995. reattach(): void;
  1996. }
  1997. /**
  1998. * Indicates that the result of a {@link PipeMetadata} transformation has changed even though the
  1999. * reference
  2000. * has not changed.
  2001. *
  2002. * The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
  2003. *
  2004. * Example:
  2005. *
  2006. * ```
  2007. * if (this._latestValue === this._latestReturnedValue) {
  2008. * return this._latestReturnedValue;
  2009. * } else {
  2010. * this._latestReturnedValue = this._latestValue;
  2011. * return WrappedValue.wrap(this._latestValue); // this will force update
  2012. * }
  2013. * ```
  2014. */
  2015. class WrappedValue {
  2016. static wrap(value: any): WrappedValue;
  2017. wrapped: any;
  2018. }
  2019. /**
  2020. * An interface which all pipes must implement.
  2021. *
  2022. * #Example
  2023. *
  2024. * ```
  2025. * class DoublePipe implements PipeTransform {
  2026. * transform(value, args = []) {
  2027. * return `${value}${value}`;
  2028. * }
  2029. * }
  2030. * ```
  2031. */
  2032. interface PipeTransform {
  2033. transform(value: any, args: any[]): any;
  2034. }
  2035. /**
  2036. * An interface that stateful pipes should implement.
  2037. *
  2038. * #Example
  2039. *
  2040. * ```
  2041. * class StatefulPipe implements PipeTransform, PipeOnDestroy {
  2042. * connection;
  2043. *
  2044. * onDestroy() {
  2045. * this.connection.release();
  2046. * }
  2047. *
  2048. * transform(value, args = []) {
  2049. * this.connection = createConnection();
  2050. * // ...
  2051. * return someValue;
  2052. * }
  2053. * }
  2054. * ```
  2055. */
  2056. interface PipeOnDestroy {
  2057. onDestroy(): void;
  2058. }
  2059. /**
  2060. * A repository of different iterable diffing strategies used by NgFor, NgClass, and others.
  2061. */
  2062. class IterableDiffers {
  2063. static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers;
  2064. /**
  2065. * Takes an array of {@link IterableDifferFactory} and returns a binding used to extend the
  2066. * inherited {@link IterableDiffers} instance with the provided factories and return a new
  2067. * {@link IterableDiffers} instance.
  2068. *
  2069. * The following example shows how to extend an existing list of factories,
  2070. * which will only be applied to the injector for this component and its children.
  2071. * This step is all that's required to make a new {@link IterableDiffer} available.
  2072. *
  2073. * # Example
  2074. *
  2075. * ```
  2076. * @Component({
  2077. * viewBindings: [
  2078. * IterableDiffers.extend([new ImmutableListDiffer()])
  2079. * ]
  2080. * })
  2081. * ```
  2082. */
  2083. static extend(factories: IterableDifferFactory[]): Binding;
  2084. factories: IterableDifferFactory[];
  2085. find(iterable: Object): IterableDifferFactory;
  2086. }
  2087. interface IterableDiffer {
  2088. diff(object: Object): any;
  2089. onDestroy(): void;
  2090. }
  2091. /**
  2092. * Provides a factory for {@link IterableDiffer}.
  2093. */
  2094. interface IterableDifferFactory {
  2095. supports(objects: Object): boolean;
  2096. create(cdRef: ChangeDetectorRef): IterableDiffer;
  2097. }
  2098. /**
  2099. * A repository of different Map diffing strategies used by NgClass, NgStyle, and others.
  2100. */
  2101. class KeyValueDiffers {
  2102. static create(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers;
  2103. /**
  2104. * Takes an array of {@link KeyValueDifferFactory} and returns a binding used to extend the
  2105. * inherited {@link KeyValueDiffers} instance with the provided factories and return a new
  2106. * {@link KeyValueDiffers} instance.
  2107. *
  2108. * The following example shows how to extend an existing list of factories,
  2109. * which will only be applied to the injector for this component and its children.
  2110. * This step is all that's required to make a new {@link KeyValueDiffer} available.
  2111. *
  2112. * # Example
  2113. *
  2114. * ```
  2115. * @Component({
  2116. * viewBindings: [
  2117. * KeyValueDiffers.extend([new ImmutableMapDiffer()])
  2118. * ]
  2119. * })
  2120. * ```
  2121. */
  2122. static extend(factories: KeyValueDifferFactory[]): Binding;
  2123. factories: KeyValueDifferFactory[];
  2124. find(kv: Object): KeyValueDifferFactory;
  2125. }
  2126. interface KeyValueDiffer {
  2127. diff(object: Object): void;
  2128. onDestroy(): void;
  2129. }
  2130. /**
  2131. * Provides a factory for {@link KeyValueDiffer}.
  2132. */
  2133. interface KeyValueDifferFactory {
  2134. supports(objects: Object): boolean;
  2135. create(cdRef: ChangeDetectorRef): KeyValueDiffer;
  2136. }
  2137. /**
  2138. * An opaque token representing the application root type in the {@link Injector}.
  2139. *
  2140. * ```
  2141. * @Component(...)
  2142. * @View(...)
  2143. * class MyApp {
  2144. * ...
  2145. * }
  2146. *
  2147. * bootstrap(MyApp).then((appRef:ApplicationRef) {
  2148. * expect(appRef.injector.get(appComponentTypeToken)).toEqual(MyApp);
  2149. * });
  2150. *
  2151. * ```
  2152. */
  2153. const APP_COMPONENT : OpaqueToken ;
  2154. /**
  2155. * Runtime representation of a type.
  2156. *
  2157. * In JavaScript a Type is a constructor function.
  2158. */
  2159. interface Type extends Function {
  2160. new(...args: any[]): any;
  2161. }
  2162. /**
  2163. * Represents a Angular's representation of an Application.
  2164. *
  2165. * `ApplicationRef` represents a running application instance. Use it to retrieve the host
  2166. * component, injector,
  2167. * or dispose of an application.
  2168. */
  2169. interface ApplicationRef {
  2170. /**
  2171. * Returns the current {@link ComponentMetadata} type.
  2172. */
  2173. hostComponentType: Type;
  2174. /**
  2175. * Returns the current {@link ComponentMetadata} instance.
  2176. */
  2177. hostComponent: any;
  2178. /**
  2179. * Dispose (un-load) the application.
  2180. */
  2181. dispose(): void;
  2182. /**
  2183. * Returns the root application {@link Injector}.
  2184. */
  2185. injector: Injector;
  2186. }
  2187. /**
  2188. * Specifies app root url for the application.
  2189. *
  2190. * Used by the {@link Compiler} when resolving HTML and CSS template URLs.
  2191. *
  2192. * This interface can be overridden by the application developer to create custom behavior.
  2193. *
  2194. * See {@link Compiler}
  2195. */
  2196. class AppRootUrl {
  2197. /**
  2198. * Returns the base URL of the currently running application.
  2199. */
  2200. value: any;
  2201. }
  2202. /**
  2203. * Used by the {@link Compiler} when resolving HTML and CSS template URLs.
  2204. *
  2205. * This interface can be overridden by the application developer to create custom behavior.
  2206. *
  2207. * See {@link Compiler}
  2208. */
  2209. class UrlResolver {
  2210. /**
  2211. * Resolves the `url` given the `baseUrl`:
  2212. * - when the `url` is null, the `baseUrl` is returned,
  2213. * - if `url` is relative ('path/to/here', './path/to/here'), the resolved url is a combination of
  2214. * `baseUrl` and `url`,
  2215. * - if `url` is absolute (it has a scheme: 'http://', 'https://' or start with '/'), the `url` is
  2216. * returned as is (ignoring the `baseUrl`)
  2217. *
  2218. * @param {string} baseUrl
  2219. * @param {string} url
  2220. * @returns {string} the resolved URL
  2221. */
  2222. resolve(baseUrl: string, url: string): string;
  2223. }
  2224. /**
  2225. * Resolve a `Type` from a {@link ComponentMetadata} into a URL.
  2226. *
  2227. * This interface can be overridden by the application developer to create custom behavior.
  2228. *
  2229. * See {@link Compiler}
  2230. */
  2231. class ComponentUrlMapper {
  2232. /**
  2233. * Returns the base URL to the component source file.
  2234. * The returned URL could be:
  2235. * - an absolute URL,
  2236. * - a path relative to the application
  2237. */
  2238. getUrl(component: Type): string;
  2239. }
  2240. /**
  2241. * Resolve a `Type` for {@link DirectiveMetadata}.
  2242. *
  2243. * This interface can be overridden by the application developer to create custom behavior.
  2244. *
  2245. * See {@link Compiler}
  2246. */
  2247. class DirectiveResolver {
  2248. /**
  2249. * Return {@link DirectiveMetadata} for a given `Type`.
  2250. */
  2251. resolve(type: Type): DirectiveMetadata;
  2252. }
  2253. /**
  2254. * ## URL Resolution
  2255. *
  2256. * ```
  2257. * var appRootUrl: AppRootUrl = ...;
  2258. * var componentUrlMapper: ComponentUrlMapper = ...;
  2259. * var urlResolver: UrlResolver = ...;
  2260. *
  2261. * var componentType: Type = ...;
  2262. * var componentAnnotation: ComponentAnnotation = ...;
  2263. * var viewAnnotation: ViewAnnotation = ...;
  2264. *
  2265. * // Resolving a URL
  2266. *
  2267. * var url = viewAnnotation.templateUrl;
  2268. * var componentUrl = componentUrlMapper.getUrl(componentType);
  2269. * var componentResolvedUrl = urlResolver.resolve(appRootUrl.value, componentUrl);
  2270. * var templateResolvedUrl = urlResolver.resolve(componetResolvedUrl, url);
  2271. * ```
  2272. */
  2273. interface Compiler {
  2274. compileInHost(componentTypeOrBinding: Type | Binding): Promise<ProtoViewRef>;
  2275. }
  2276. /**
  2277. * Entry point for creating, moving views in the view hierarchy and destroying views.
  2278. * This manager contains all recursion and delegates to helper methods
  2279. * in AppViewManagerUtils and the Renderer, so unit tests get simpler.
  2280. */
  2281. interface AppViewManager {
  2282. /**
  2283. * Returns a {@link ViewContainerRef} at the {@link ElementRef} location.
  2284. */
  2285. getViewContainer(location: ElementRef): ViewContainerRef;
  2286. /**
  2287. * Return the first child element of the host element view.
  2288. */
  2289. getHostElement(hostViewRef: HostViewRef): ElementRef;
  2290. /**
  2291. * Returns an ElementRef for the element with the given variable name
  2292. * in the current view.
  2293. *
  2294. * - `hostLocation`: {@link ElementRef} of any element in the View which defines the scope of
  2295. * search.
  2296. * - `variableName`: Name of the variable to locate.
  2297. * - Returns {@link ElementRef} of the found element or null. (Throws if not found.)
  2298. */
  2299. getNamedElementInComponentView(hostLocation: ElementRef, variableName: string): ElementRef;
  2300. /**
  2301. * Returns the component instance for a given element.
  2302. *
  2303. * The component is the execution context as seen by an expression at that {@link ElementRef}
  2304. * location.
  2305. */
  2306. getComponent(hostLocation: ElementRef): any;
  2307. /**
  2308. * Load component view into existing element.
  2309. *
  2310. * Use this if a host element is already in the DOM and it is necessary to upgrade
  2311. * the element into Angular component by attaching a view but reusing the existing element.
  2312. *
  2313. * - `hostProtoViewRef`: {@link ProtoViewRef} Proto view to use in creating a view for this
  2314. * component.
  2315. * - `overrideSelector`: (optional) selector to use in locating the existing element to load
  2316. * the view into. If not specified use the selector in the component definition of the
  2317. * `hostProtoView`.
  2318. * - injector: {@link Injector} to use as parent injector for the view.
  2319. *
  2320. * See {@link AppViewManager#destroyRootHostView}.
  2321. *
  2322. * ## Example
  2323. *
  2324. * ```
  2325. * @ng.Component({
  2326. * selector: 'child-component'
  2327. * })
  2328. * @ng.View({
  2329. * template: 'Child'
  2330. * })
  2331. * class ChildComponent {
  2332. *
  2333. * }
  2334. *
  2335. * @ng.Component({
  2336. * selector: 'my-app'
  2337. * })
  2338. * @ng.View({
  2339. * template: `
  2340. * Parent (<some-component></some-component>)
  2341. * `
  2342. * })
  2343. * class MyApp {
  2344. * viewRef: ng.ViewRef;
  2345. *
  2346. * constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) {
  2347. * compiler.compileInHost(ChildComponent).then((protoView: ng.ProtoViewRef) => {
  2348. * this.viewRef = appViewManager.createRootHostView(protoView, 'some-component', null);
  2349. * })
  2350. * }
  2351. *
  2352. * onDestroy() {
  2353. * this.appViewManager.destroyRootHostView(this.viewRef);
  2354. * this.viewRef = null;
  2355. * }
  2356. * }
  2357. *
  2358. * ng.bootstrap(MyApp);
  2359. * ```
  2360. */
  2361. createRootHostView(hostProtoViewRef: ProtoViewRef, overrideSelector: string, injector: Injector): HostViewRef;
  2362. /**
  2363. * Remove the View created with {@link AppViewManager#createRootHostView}.
  2364. */
  2365. destroyRootHostView(hostViewRef: HostViewRef): void;
  2366. /**
  2367. * See {@link AppViewManager#destroyViewInContainer}.
  2368. */
  2369. createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number, templateRef: TemplateRef): ViewRef;
  2370. /**
  2371. * See {@link AppViewManager#destroyViewInContainer}.
  2372. */
  2373. createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number, protoViewRef: ProtoViewRef, imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef;
  2374. /**
  2375. * See {@link AppViewManager#createViewInContainer}.
  2376. */
  2377. destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number): void;
  2378. /**
  2379. * See {@link AppViewManager#detachViewInContainer}.
  2380. */
  2381. attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number, viewRef: ViewRef): ViewRef;
  2382. /**
  2383. * See {@link AppViewManager#attachViewInContainer}.
  2384. */
  2385. detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef;
  2386. }
  2387. /**
  2388. * An iterable and observable live list of components in the DOM.
  2389. *
  2390. * A QueryList contains a live list of child directives in the DOM of a directive.
  2391. * The directives are kept in depth-first pre-order traversal of the DOM.
  2392. *
  2393. * The `QueryList` is iterable, therefore it can be used in both javascript code with `for..of` loop
  2394. * as well as in template with `*ng-for="of"` directive.
  2395. *
  2396. * QueryList is updated as part of the change-detection cycle of a directive. Since change detection
  2397. * happens after construction of a directive, QueryList will always be empty when observed in the
  2398. * constructor.
  2399. *
  2400. *
  2401. * NOTE: In the future this class will implement an `Observable` interface. For now it uses a plain
  2402. * list of observable callbacks.
  2403. *
  2404. * # Example:
  2405. *
  2406. * Assume that `<tabs>` component would like to get a list its children which are `<pane>`
  2407. * components as shown in this example:
  2408. *
  2409. * ```html
  2410. * <tabs>
  2411. * <pane title="Overview">...</pane>
  2412. * <pane *ng-for="#o of objects" [title]="o.title">{{o.text}}</pane>
  2413. * </tabs>
  2414. * ```
  2415. *
  2416. * In the above example the list of `<tabs>` elements needs to get a list of `<pane>` elements so
  2417. * that it could render tabs with the correct titles and in the correct order.
  2418. *
  2419. * A possible solution would be for a `<pane>` to inject `<tabs>` component and then register itself
  2420. * with `<tabs>` component's on `hydrate` and deregister on `dehydrate` event. While a reasonable
  2421. * approach, this would only work partialy since `*ng-for` could rearrange the list of `<pane>`
  2422. * components which would not be reported to `<tabs>` component and thus the list of `<pane>`
  2423. * components would be out of sync with respect to the list of `<pane>` elements.
  2424. *
  2425. * A preferred solution is to inject a `QueryList` which is a live list of directives in the
  2426. * component`s light DOM.
  2427. *
  2428. * ```javascript
  2429. * @Component({
  2430. * selector: 'tabs'
  2431. * })
  2432. * @View({
  2433. * template: `
  2434. * <ul>
  2435. * <li *ng-for="#pane of panes">{{pane.title}}</li>
  2436. * </ul>
  2437. * <content></content>
  2438. * `
  2439. * })
  2440. * class Tabs {
  2441. * panes: QueryList<Pane>
  2442. *
  2443. * constructor(@Query(Pane) panes:QueryList<Pane>) {
  2444. * this.panes = panes;
  2445. * }
  2446. * }
  2447. *
  2448. * @Component({
  2449. * selector: 'pane',
  2450. * properties: ['title']
  2451. * })
  2452. * @View(...)
  2453. * class Pane {
  2454. * title:string;
  2455. * }
  2456. * ```
  2457. */
  2458. class QueryList<T> {
  2459. reset(newList: T[]): void;
  2460. add(obj: T): void;
  2461. fireCallbacks(): void;
  2462. onChange(callback: () => void): void;
  2463. removeCallback(callback: () => void): void;
  2464. toString(): string;
  2465. length: number;
  2466. first: T;
  2467. last: T;
  2468. map<U>(fn: (item: T) => U): U[];
  2469. }
  2470. /**
  2471. * Service for dynamically loading a Component into an arbitrary position in the internal Angular
  2472. * application tree.
  2473. */
  2474. class DynamicComponentLoader {
  2475. /**
  2476. * Loads a root component that is placed at the first element that matches the component's
  2477. * selector.
  2478. *
  2479. * - `typeOrBinding` `Type` \ {@link Binding} - representing the component to load.
  2480. * - `overrideSelector` (optional) selector to load the component at (or use
  2481. * `@Component.selector`) The selector can be anywhere (i.e. outside the current component.)
  2482. * - `injector` {@link Injector} - optional injector to use for the component.
  2483. *
  2484. * The loaded component receives injection normally as a hosted view.
  2485. *
  2486. *
  2487. * ## Example
  2488. *
  2489. * ```
  2490. * @ng.Component({
  2491. * selector: 'child-component'
  2492. * })
  2493. * @ng.View({
  2494. * template: 'Child'
  2495. * })
  2496. * class ChildComponent {
  2497. * }
  2498. *
  2499. *
  2500. *
  2501. * @ng.Component({
  2502. * selector: 'my-app'
  2503. * })
  2504. * @ng.View({
  2505. * template: `
  2506. * Parent (<child id="child"></child>)
  2507. * `
  2508. * })
  2509. * class MyApp {
  2510. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, injector: ng.Injector) {
  2511. * dynamicComponentLoader.loadAsRoot(ChildComponent, '#child', injector);
  2512. * }
  2513. * }
  2514. *
  2515. * ng.bootstrap(MyApp);
  2516. * ```
  2517. *
  2518. * Resulting DOM:
  2519. *
  2520. * ```
  2521. * <my-app>
  2522. * Parent (
  2523. * <child id="child">
  2524. * Child
  2525. * </child>
  2526. * )
  2527. * </my-app>
  2528. * ```
  2529. */
  2530. loadAsRoot(typeOrBinding: Type | Binding, overrideSelector: string, injector: Injector): Promise<ComponentRef>;
  2531. /**
  2532. * Loads a component into the component view of the provided ElementRef next to the element
  2533. * with the given name.
  2534. *
  2535. * The loaded component receives injection normally as a hosted view.
  2536. *
  2537. * ## Example
  2538. *
  2539. * ```
  2540. * @ng.Component({
  2541. * selector: 'child-component'
  2542. * })
  2543. * @ng.View({
  2544. * template: 'Child'
  2545. * })
  2546. * class ChildComponent {
  2547. * }
  2548. *
  2549. *
  2550. * @ng.Component({
  2551. * selector: 'my-app'
  2552. * })
  2553. * @ng.View({
  2554. * template: `
  2555. * Parent (<div #child></div>)
  2556. * `
  2557. * })
  2558. * class MyApp {
  2559. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
  2560. * dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
  2561. * }
  2562. * }
  2563. *
  2564. * ng.bootstrap(MyApp);
  2565. * ```
  2566. *
  2567. * Resulting DOM:
  2568. *
  2569. * ```
  2570. * <my-app>
  2571. * Parent (
  2572. * <div #child="" class="ng-binding"></div>
  2573. * <child-component class="ng-binding">Child</child-component>
  2574. * )
  2575. * </my-app>
  2576. * ```
  2577. */
  2578. loadIntoLocation(typeOrBinding: Type | Binding, hostLocation: ElementRef, anchorName: string, bindings?: ResolvedBinding[]): Promise<ComponentRef>;
  2579. /**
  2580. * Loads a component next to the provided ElementRef.
  2581. *
  2582. * The loaded component receives injection normally as a hosted view.
  2583. *
  2584. *
  2585. * ## Example
  2586. *
  2587. * ```
  2588. * @ng.Component({
  2589. * selector: 'child-component'
  2590. * })
  2591. * @ng.View({
  2592. * template: 'Child'
  2593. * })
  2594. * class ChildComponent {
  2595. * }
  2596. *
  2597. *
  2598. * @ng.Component({
  2599. * selector: 'my-app'
  2600. * })
  2601. * @ng.View({
  2602. * template: `Parent`
  2603. * })
  2604. * class MyApp {
  2605. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
  2606. * dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
  2607. * }
  2608. * }
  2609. *
  2610. * ng.bootstrap(MyApp);
  2611. * ```
  2612. *
  2613. * Resulting DOM:
  2614. *
  2615. * ```
  2616. * <my-app>Parent</my-app>
  2617. * <child-component>Child</child-component>
  2618. * ```
  2619. */
  2620. loadNextToLocation(typeOrBinding: Type | Binding, location: ElementRef, bindings?: ResolvedBinding[]): Promise<ComponentRef>;
  2621. }
  2622. /**
  2623. * Provides access to explicitly trigger change detection in an application.
  2624. *
  2625. * By default, `Zone` triggers change detection in Angular on each virtual machine (VM) turn. When
  2626. * testing, or in some
  2627. * limited application use cases, a developer can also trigger change detection with the
  2628. * `lifecycle.tick()` method.
  2629. *
  2630. * Each Angular application has a single `LifeCycle` instance.
  2631. *
  2632. * # Example
  2633. *
  2634. * This is a contrived example, since the bootstrap automatically runs inside of the `Zone`, which
  2635. * invokes
  2636. * `lifecycle.tick()` on your behalf.
  2637. *
  2638. * ```javascript
  2639. * bootstrap(MyApp).then((ref:ComponentRef) => {
  2640. * var lifeCycle = ref.injector.get(LifeCycle);
  2641. * var myApp = ref.instance;
  2642. *
  2643. * ref.doSomething();
  2644. * lifecycle.tick();
  2645. * });
  2646. * ```
  2647. */
  2648. class LifeCycle {
  2649. /**
  2650. * @private
  2651. */
  2652. registerWith(zone: NgZone, changeDetector?: ChangeDetector): void;
  2653. /**
  2654. * Invoke this method to explicitly process change detection and its side-effects.
  2655. *
  2656. * In development mode, `tick()` also performs a second change detection cycle to ensure that no
  2657. * further
  2658. * changes are detected. If additional changes are picked up during this second cycle, bindings
  2659. * in
  2660. * the app have
  2661. * side-effects that cannot be resolved in a single change detection pass. In this case, Angular
  2662. * throws an error,
  2663. * since an Angular application can only have one change detection pass during which all change
  2664. * detection must
  2665. * complete.
  2666. */
  2667. tick(): void;
  2668. }
  2669. /**
  2670. * Reference to the element.
  2671. *
  2672. * Represents an opaque reference to the underlying element. The element is a DOM ELement in
  2673. * a Browser, but may represent other types on other rendering platforms. In the browser the
  2674. * `ElementRef` can be sent to the web-worker. Web Workers can not have references to the
  2675. * DOM Elements.
  2676. */
  2677. class ElementRef implements RenderElementRef {
  2678. /**
  2679. * Reference to the {@link ViewRef} where the `ElementRef` is inside of.
  2680. */
  2681. parentView: ViewRef;
  2682. /**
  2683. * Index of the element inside the {@link ViewRef}.
  2684. *
  2685. * This is used internally by the Angular framework to locate elements.
  2686. */
  2687. boundElementIndex: number;
  2688. /**
  2689. * Index of the element inside the `RenderViewRef`.
  2690. *
  2691. * This is used internally by the Angular framework to locate elements.
  2692. */
  2693. renderBoundElementIndex: number;
  2694. renderView: RenderViewRef;
  2695. /**
  2696. * Returns the native Element implementation.
  2697. *
  2698. * In the browser this represents the DOM Element.
  2699. *
  2700. * The `nativeElement` can be used as an escape hatch when direct DOM manipulation is needed. Use
  2701. * this with caution, as it creates tight coupling between your application and the Browser, which
  2702. * will not work in WebWorkers.
  2703. *
  2704. * NOTE: This method will return null in the webworker scenario!
  2705. */
  2706. nativeElement: any;
  2707. }
  2708. /**
  2709. * Reference to a template within a component.
  2710. *
  2711. * Represents an opaque reference to the underlying template that can
  2712. * be instantiated using the {@link ViewContainerRef}.
  2713. */
  2714. class TemplateRef {
  2715. /**
  2716. * The location of the template
  2717. */
  2718. elementRef: ElementRef;
  2719. protoViewRef: ProtoViewRef;
  2720. /**
  2721. * Whether this template has a local variable with the given name
  2722. */
  2723. hasLocal(name: string): boolean;
  2724. }
  2725. /**
  2726. * A reference to an Angular View.
  2727. *
  2728. * A View is a fundamental building block of Application UI. A View is the smallest set of
  2729. * elements which are created and destroyed together. A View can change properties on the elements
  2730. * within the view, but it can not change the structure of those elements.
  2731. *
  2732. * To change structure of the elements, the Views can contain zero or more {@link ViewContainerRef}s
  2733. * which allow the views to be nested.
  2734. *
  2735. * ## Example
  2736. *
  2737. * Given this template
  2738. *
  2739. * ```
  2740. * Count: {{items.length}}
  2741. * <ul>
  2742. * <li *ng-for="var item of items">{{item}}</li>
  2743. * </ul>
  2744. * ```
  2745. *
  2746. * The above example we have two {@link ProtoViewRef}s:
  2747. *
  2748. * Outter {@link ProtoViewRef}:
  2749. * ```
  2750. * Count: {{items.length}}
  2751. * <ul>
  2752. * <template ng-for var-item [ng-for-of]="items"></template>
  2753. * </ul>
  2754. * ```
  2755. *
  2756. * Inner {@link ProtoViewRef}:
  2757. * ```
  2758. * <li>{{item}}</li>
  2759. * ```
  2760. *
  2761. * Notice that the original template is broken down into two separate {@link ProtoViewRef}s.
  2762. *
  2763. * The outter/inner {@link ProtoViewRef}s are then assembled into views like so:
  2764. *
  2765. * ```
  2766. * <!-- ViewRef: outer-0 -->
  2767. * Count: 2
  2768. * <ul>
  2769. * <template view-container-ref></template>
  2770. * <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
  2771. * <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
  2772. * </ul>
  2773. * <!-- /ViewRef: outer-0 -->
  2774. * ```
  2775. */
  2776. interface ViewRef extends HostViewRef {
  2777. /**
  2778. * Return `RenderViewRef`
  2779. */
  2780. render: RenderViewRef;
  2781. /**
  2782. * Return `RenderFragmentRef`
  2783. */
  2784. renderFragment: RenderFragmentRef;
  2785. /**
  2786. * Set local variable in a view.
  2787. *
  2788. * - `contextName` - Name of the local variable in a view.
  2789. * - `value` - Value for the local variable in a view.
  2790. */
  2791. setLocal(contextName: string, value: any): void;
  2792. }
  2793. interface HostViewRef {
  2794. }
  2795. /**
  2796. * A reference to an Angular ProtoView.
  2797. *
  2798. * A ProtoView is a reference to a template for easy creation of views.
  2799. * (See {@link AppViewManager#createViewInContainer `AppViewManager#createViewInContainer`} and
  2800. * {@link AppViewManager#createRootHostView `AppViewManager#createRootHostView`}).
  2801. *
  2802. * A `ProtoView` is a factory for creating `View`s.
  2803. *
  2804. * ## Example
  2805. *
  2806. * Given this template
  2807. *
  2808. * ```
  2809. * Count: {{items.length}}
  2810. * <ul>
  2811. * <li *ng-for="var item of items">{{item}}</li>
  2812. * </ul>
  2813. * ```
  2814. *
  2815. * The above example we have two {@link ProtoViewRef}s:
  2816. *
  2817. * Outter {@link ProtoViewRef}:
  2818. * ```
  2819. * Count: {{items.length}}
  2820. * <ul>
  2821. * <template ng-for var-item [ng-for-of]="items"></template>
  2822. * </ul>
  2823. * ```
  2824. *
  2825. * Inner {@link ProtoViewRef}:
  2826. * ```
  2827. * <li>{{item}}</li>
  2828. * ```
  2829. *
  2830. * Notice that the original template is broken down into two separate {@link ProtoViewRef}s.
  2831. */
  2832. interface ProtoViewRef {
  2833. }
  2834. /**
  2835. * A location where {@link ViewRef}s can be attached.
  2836. *
  2837. * A `ViewContainerRef` represents a location in a {@link ViewRef} where other child
  2838. * {@link ViewRef}s can be inserted. Adding and removing views is the only way of structurally
  2839. * changing the rendered DOM of the application.
  2840. */
  2841. interface ViewContainerRef {
  2842. viewManager: AppViewManager;
  2843. element: ElementRef;
  2844. /**
  2845. * Remove all {@link ViewRef}s at current location.
  2846. */
  2847. clear(): void;
  2848. /**
  2849. * Return a {@link ViewRef} at specific index.
  2850. */
  2851. get(index: number): ViewRef;
  2852. /**
  2853. * Returns number of {@link ViewRef}s currently attached at this location.
  2854. */
  2855. length: number;
  2856. /**
  2857. * Create and insert a {@link ViewRef} into the view-container.
  2858. *
  2859. * - `protoViewRef` (optional) {@link ProtoViewRef} - The `ProtoView` to use for creating
  2860. * `View` to be inserted at this location. If `ViewContainer` is created at a location
  2861. * of inline template, then `protoViewRef` is the `ProtoView` of the template.
  2862. * - `atIndex` (optional) `number` - location of insertion point. (Or at the end if unspecified.)
  2863. * - `context` (optional) {@link ElementRef} - Context (for expression evaluation) from the
  2864. * {@link ElementRef} location. (Or current context if unspecified.)
  2865. * - `bindings` (optional) Array of {@link ResolvedBinding} - Used for configuring
  2866. * `ElementInjector`.
  2867. *
  2868. * Returns newly created {@link ViewRef}.
  2869. */
  2870. createEmbeddedView(templateRef: TemplateRef, atIndex?: number): ViewRef;
  2871. createHostView(protoViewRef?: ProtoViewRef, atIndex?: number, dynamicallyCreatedBindings?: ResolvedBinding[]): HostViewRef;
  2872. /**
  2873. * Insert a {@link ViewRef} at specefic index.
  2874. *
  2875. * The index is location at which the {@link ViewRef} should be attached. If omitted it is
  2876. * inserted at the end.
  2877. *
  2878. * Returns the inserted {@link ViewRef}.
  2879. */
  2880. insert(viewRef: ViewRef, atIndex?: number): ViewRef;
  2881. /**
  2882. * Return the index of already inserted {@link ViewRef}.
  2883. */
  2884. indexOf(viewRef: ViewRef): number;
  2885. /**
  2886. * Remove a {@link ViewRef} at specific index.
  2887. *
  2888. * If the index is omitted last {@link ViewRef} is removed.
  2889. */
  2890. remove(atIndex?: number): void;
  2891. /**
  2892. * The method can be used together with insert to implement a view move, i.e.
  2893. * moving the dom nodes while the directives in the view stay intact.
  2894. */
  2895. detach(atIndex?: number): ViewRef;
  2896. }
  2897. /**
  2898. * Angular's reference to a component instance.
  2899. *
  2900. * `ComponentRef` represents a component instance lifecycle and meta information.
  2901. */
  2902. interface ComponentRef {
  2903. /**
  2904. * Location of the component host element.
  2905. */
  2906. location: ElementRef;
  2907. /**
  2908. * Instance of component.
  2909. */
  2910. instance: any;
  2911. /**
  2912. * Returns the host {@link ViewRef}.
  2913. */
  2914. hostView: HostViewRef;
  2915. /**
  2916. * Dispose of the component instance.
  2917. */
  2918. dispose(): void;
  2919. }
  2920. /**
  2921. * A wrapper around zones that lets you schedule tasks after it has executed a task.
  2922. *
  2923. * The wrapper maintains an "inner" and an "mount" `Zone`. The application code will executes
  2924. * in the "inner" zone unless `runOutsideAngular` is explicitely called.
  2925. *
  2926. * A typical application will create a singleton `NgZone`. The outer `Zone` is a fork of the root
  2927. * `Zone`. The default `onTurnDone` runs the Angular change detection.
  2928. */
  2929. class NgZone {
  2930. /**
  2931. * Sets the zone hook that is called just before Angular event turn starts.
  2932. * It is called once per browser event.
  2933. */
  2934. overrideOnTurnStart(onTurnStartFn: Function): void;
  2935. /**
  2936. * Sets the zone hook that is called immediately after Angular processes
  2937. * all pending microtasks.
  2938. */
  2939. overrideOnTurnDone(onTurnDoneFn: Function): void;
  2940. /**
  2941. * Sets the zone hook that is called immediately after the last turn in
  2942. * an event completes. At this point Angular will no longer attempt to
  2943. * sync the UI. Any changes to the data model will not be reflected in the
  2944. * DOM. `onEventDoneFn` is executed outside Angular zone.
  2945. *
  2946. * This hook is useful for validating application state (e.g. in a test).
  2947. */
  2948. overrideOnEventDone(onEventDoneFn: Function, opt_waitForAsync: boolean): void;
  2949. /**
  2950. * Sets the zone hook that is called when an error is uncaught in the
  2951. * Angular zone. The first argument is the error. The second argument is
  2952. * the stack trace.
  2953. */
  2954. overrideOnErrorHandler(errorHandlingFn: Function): void;
  2955. /**
  2956. * Runs `fn` in the inner zone and returns whatever it returns.
  2957. *
  2958. * In a typical app where the inner zone is the Angular zone, this allows one to make use of the
  2959. * Angular's auto digest mechanism.
  2960. *
  2961. * ```
  2962. * var zone: NgZone = [ref to the application zone];
  2963. *
  2964. * zone.run(() => {
  2965. * // the change detection will run after this function and the microtasks it enqueues have
  2966. * executed.
  2967. * });
  2968. * ```
  2969. */
  2970. run(fn: () => any): any;
  2971. /**
  2972. * Runs `fn` in the outer zone and returns whatever it returns.
  2973. *
  2974. * In a typical app where the inner zone is the Angular zone, this allows one to escape Angular's
  2975. * auto-digest mechanism.
  2976. *
  2977. * ```
  2978. * var zone: NgZone = [ref to the application zone];
  2979. *
  2980. * zone.runOutsideAngular(() => {
  2981. * element.onClick(() => {
  2982. * // Clicking on the element would not trigger the change detection
  2983. * });
  2984. * });
  2985. * ```
  2986. */
  2987. runOutsideAngular(fn: () => any): any;
  2988. }
  2989. class Observable {
  2990. observer(generator: any): Object;
  2991. }
  2992. /**
  2993. * Use Rx.Observable but provides an adapter to make it work as specified here:
  2994. * https://github.com/jhusain/observable-spec
  2995. *
  2996. * Once a reference implementation of the spec is available, switch to it.
  2997. */
  2998. class EventEmitter extends Observable {
  2999. observer(generator: any): Rx.IDisposable;
  3000. toRx(): Rx.Observable<any>;
  3001. next(value: any): void;
  3002. throw(error: any): void;
  3003. return(value?: any): void;
  3004. }
  3005. /**
  3006. * A parameter metadata that specifies a dependency.
  3007. *
  3008. * ```
  3009. * class AComponent {
  3010. * constructor(@Inject(MyService) aService:MyService) {}
  3011. * }
  3012. * ```
  3013. */
  3014. class InjectMetadata {
  3015. token: any;
  3016. toString(): string;
  3017. }
  3018. /**
  3019. * A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if
  3020. * the dependency is not found.
  3021. *
  3022. * ```
  3023. * class AComponent {
  3024. * constructor(@Optional() aService:MyService) {
  3025. * this.aService = aService;
  3026. * }
  3027. * }
  3028. * ```
  3029. */
  3030. class OptionalMetadata {
  3031. toString(): string;
  3032. }
  3033. /**
  3034. * A marker metadata that marks a class as available to `Injector` for creation. Used by tooling
  3035. * for generating constructor stubs.
  3036. *
  3037. * ```
  3038. * class NeedsService {
  3039. * constructor(svc:UsefulService) {}
  3040. * }
  3041. *
  3042. * @Injectable
  3043. * class UsefulService {}
  3044. * ```
  3045. */
  3046. class InjectableMetadata {
  3047. }
  3048. /**
  3049. * Specifies that an injector should retrieve a dependency from itself.
  3050. *
  3051. * ## Example
  3052. *
  3053. * ```
  3054. * class Dependency {
  3055. * }
  3056. *
  3057. * class NeedsDependency {
  3058. * constructor(public @Self() dependency:Dependency) {}
  3059. * }
  3060. *
  3061. * var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]);
  3062. * var nd = inj.get(NeedsDependency);
  3063. * expect(nd.dependency).toBeAnInstanceOf(Dependency);
  3064. * ```
  3065. */
  3066. class SelfMetadata {
  3067. toString(): string;
  3068. }
  3069. /**
  3070. * Specifies that an injector should retrieve a dependency from any injector until reaching the
  3071. * closest host.
  3072. *
  3073. * ## Example
  3074. *
  3075. * ```
  3076. * class Dependency {
  3077. * }
  3078. *
  3079. * class NeedsDependency {
  3080. * constructor(public @Host() dependency:Dependency) {}
  3081. * }
  3082. *
  3083. * var parent = Injector.resolveAndCreate([
  3084. * bind(Dependency).toClass(HostDependency)
  3085. * ]);
  3086. * var child = parent.resolveAndCreateChild([]);
  3087. * var grandChild = child.resolveAndCreateChild([NeedsDependency, Depedency]);
  3088. * var nd = grandChild.get(NeedsDependency);
  3089. * expect(nd.dependency).toBeAnInstanceOf(HostDependency);
  3090. * ```
  3091. */
  3092. class HostMetadata {
  3093. toString(): string;
  3094. }
  3095. /**
  3096. * Specifies that the dependency resolution should start from the parent injector.
  3097. *
  3098. * ## Example
  3099. *
  3100. *
  3101. * ```
  3102. * class Service {}
  3103. *
  3104. * class ParentService implements Service {
  3105. * }
  3106. *
  3107. * class ChildService implements Service {
  3108. * constructor(public @SkipSelf() parentService:Service) {}
  3109. * }
  3110. *
  3111. * var parent = Injector.resolveAndCreate([
  3112. * bind(Service).toClass(ParentService)
  3113. * ]);
  3114. * var child = parent.resolveAndCreateChild([
  3115. * bind(Service).toClass(ChildSerice)
  3116. * ]);
  3117. * var s = child.get(Service);
  3118. * expect(s).toBeAnInstanceOf(ChildService);
  3119. * expect(s.parentService).toBeAnInstanceOf(ParentService);
  3120. * ```
  3121. */
  3122. class SkipSelfMetadata {
  3123. toString(): string;
  3124. }
  3125. /**
  3126. * `DependencyMetadata is used by the framework to extend DI.
  3127. *
  3128. * Only metadata implementing `DependencyMetadata` are added to the list of dependency
  3129. * properties.
  3130. *
  3131. * For example:
  3132. *
  3133. * ```
  3134. * class Exclude extends DependencyMetadata {}
  3135. * class NotDependencyProperty {}
  3136. *
  3137. * class AComponent {
  3138. * constructor(@Exclude @NotDependencyProperty aService:AService) {}
  3139. * }
  3140. * ```
  3141. *
  3142. * will create the following dependency:
  3143. *
  3144. * ```
  3145. * new Dependency(Key.get(AService), [new Exclude()])
  3146. * ```
  3147. *
  3148. * The framework can use `new Exclude()` to handle the `aService` dependency
  3149. * in a specific way.
  3150. */
  3151. class DependencyMetadata {
  3152. token: any;
  3153. }
  3154. /**
  3155. * Allows to refer to references which are not yet defined.
  3156. *
  3157. * This situation arises when the key which we need te refer to for the purposes of DI is declared,
  3158. * but not yet defined.
  3159. *
  3160. * ## Example:
  3161. *
  3162. * ```
  3163. * class Door {
  3164. * // Incorrect way to refer to a reference which is defined later.
  3165. * // This fails because `Lock` is undefined at this point.
  3166. * constructor(lock:Lock) { }
  3167. *
  3168. * // Correct way to refer to a reference which is defined later.
  3169. * // The reference needs to be captured in a closure.
  3170. * constructor(@Inject(forwardRef(() => Lock)) lock:Lock) { }
  3171. * }
  3172. *
  3173. * // Only at this point the lock is defined.
  3174. * class Lock {
  3175. * }
  3176. * ```
  3177. */
  3178. function forwardRef(forwardRefFn: ForwardRefFn) : Type ;
  3179. /**
  3180. * Lazily retrieve the reference value.
  3181. *
  3182. * See: {@link forwardRef}
  3183. */
  3184. function resolveForwardRef(type: any) : any ;
  3185. interface ForwardRefFn {
  3186. (): any;
  3187. }
  3188. /**
  3189. * A dependency injection container used for resolving dependencies.
  3190. *
  3191. * An `Injector` is a replacement for a `new` operator, which can automatically resolve the
  3192. * constructor dependencies.
  3193. * In typical use, application code asks for the dependencies in the constructor and they are
  3194. * resolved by the `Injector`.
  3195. *
  3196. * ## Example:
  3197. *
  3198. * Suppose that we want to inject an `Engine` into class `Car`, we would define it like this:
  3199. *
  3200. * ```javascript
  3201. * class Engine {
  3202. * }
  3203. *
  3204. * class Car {
  3205. * constructor(@Inject(Engine) engine) {
  3206. * }
  3207. * }
  3208. *
  3209. * ```
  3210. *
  3211. * Next we need to write the code that creates and instantiates the `Injector`. We then ask for the
  3212. * `root` object, `Car`, so that the `Injector` can recursively build all of that object's
  3213. * dependencies.
  3214. *
  3215. * ```javascript
  3216. * main() {
  3217. * var injector = Injector.resolveAndCreate([Car, Engine]);
  3218. *
  3219. * // Get a reference to the `root` object, which will recursively instantiate the tree.
  3220. * var car = injector.get(Car);
  3221. * }
  3222. * ```
  3223. * Notice that we don't use the `new` operator because we explicitly want to have the `Injector`
  3224. * resolve all of the object's dependencies automatically.
  3225. */
  3226. class Injector {
  3227. /**
  3228. * Turns a list of binding definitions into an internal resolved list of resolved bindings.
  3229. *
  3230. * A resolution is a process of flattening multiple nested lists and converting individual
  3231. * bindings into a list of {@link ResolvedBinding}s. The resolution can be cached by `resolve`
  3232. * for the {@link Injector} for performance-sensitive code.
  3233. *
  3234. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  3235. * recursive list of more bindings.
  3236. *
  3237. * The returned list is sparse, indexed by `id` for the {@link Key}. It is generally not useful to
  3238. * application code
  3239. * other than for passing it to {@link Injector} functions that require resolved binding lists,
  3240. * such as
  3241. * `fromResolvedBindings` and `createChildFromResolved`.
  3242. */
  3243. static resolve(bindings: Array<Type | Binding | any[]>): ResolvedBinding[];
  3244. /**
  3245. * Resolves bindings and creates an injector based on those bindings. This function is slower than
  3246. * the corresponding `fromResolvedBindings` because it needs to resolve bindings first. See
  3247. * `resolve`
  3248. * for the {@link Injector}.
  3249. *
  3250. * Prefer `fromResolvedBindings` in performance-critical code that creates lots of injectors.
  3251. *
  3252. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  3253. * recursive list of more
  3254. * bindings.
  3255. * @param `depProvider`
  3256. */
  3257. static resolveAndCreate(bindings: Array<Type | Binding | any[]>, depProvider?: DependencyProvider): Injector;
  3258. /**
  3259. * Creates an injector from previously resolved bindings. This bypasses resolution and flattening.
  3260. * This API is the recommended way to construct injectors in performance-sensitive parts.
  3261. *
  3262. * @param `bindings` A sparse list of {@link ResolvedBinding}s. See `resolve` for the
  3263. * {@link Injector}.
  3264. * @param `depProvider`
  3265. */
  3266. static fromResolvedBindings(bindings: ResolvedBinding[], depProvider?: DependencyProvider): Injector;
  3267. /**
  3268. * Returns debug information about the injector.
  3269. *
  3270. * This information is included into exceptions thrown by the injector.
  3271. */
  3272. debugContext(): any;
  3273. /**
  3274. * Retrieves an instance from the injector.
  3275. *
  3276. * @param `token`: usually the `Type` of an object. (Same as the token used while setting up a
  3277. * binding).
  3278. * @returns an instance represented by the token. Throws if not found.
  3279. */
  3280. get(token: any): any;
  3281. /**
  3282. * Retrieves an instance from the injector.
  3283. *
  3284. * @param `token`: usually a `Type`. (Same as the token used while setting up a binding).
  3285. * @returns an instance represented by the token. Returns `null` if not found.
  3286. */
  3287. getOptional(token: any): any;
  3288. /**
  3289. * Retrieves an instance from the injector.
  3290. *
  3291. * @param `index`: index of an instance.
  3292. * @returns an instance represented by the index. Throws if not found.
  3293. */
  3294. getAt(index: number): any;
  3295. /**
  3296. * Direct parent of this injector.
  3297. */
  3298. parent: Injector;
  3299. /**
  3300. * Internal. Do not use.
  3301. *
  3302. * We return `any` not to export the InjectorStrategy type.
  3303. */
  3304. internalStrategy: any;
  3305. /**
  3306. * Creates a child injector and loads a new set of bindings into it.
  3307. *
  3308. * A resolution is a process of flattening multiple nested lists and converting individual
  3309. * bindings into a list of {@link ResolvedBinding}s. The resolution can be cached by `resolve`
  3310. * for the {@link Injector} for performance-sensitive code.
  3311. *
  3312. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  3313. * recursive list of more bindings.
  3314. * @param `depProvider`
  3315. */
  3316. resolveAndCreateChild(bindings: Array<Type | Binding | any[]>, depProvider?: DependencyProvider): Injector;
  3317. /**
  3318. * Creates a child injector and loads a new set of {@link ResolvedBinding}s into it.
  3319. *
  3320. * @param `bindings`: A sparse list of {@link ResolvedBinding}s.
  3321. * See `resolve` for the {@link Injector}.
  3322. * @param `depProvider`
  3323. * @returns a new child {@link Injector}.
  3324. */
  3325. createChildFromResolved(bindings: ResolvedBinding[], depProvider?: DependencyProvider): Injector;
  3326. /**
  3327. * Resolves a binding and instantiates an object in the context of the injector.
  3328. *
  3329. * @param `binding`: either a type or a binding.
  3330. * @returns an object created using binding.
  3331. */
  3332. resolveAndInstantiate(binding: Type | Binding): any;
  3333. /**
  3334. * Instantiates an object using a resolved bindin in the context of the injector.
  3335. *
  3336. * @param `binding`: a resolved binding
  3337. * @returns an object created using binding.
  3338. */
  3339. instantiateResolved(binding: ResolvedBinding): any;
  3340. displayName: string;
  3341. toString(): string;
  3342. }
  3343. class ProtoInjector {
  3344. numberOfBindings: number;
  3345. getBindingAtIndex(index: number): any;
  3346. }
  3347. class BindingWithVisibility {
  3348. binding: ResolvedBinding;
  3349. visibility: Visibility;
  3350. getKeyId(): number;
  3351. }
  3352. /**
  3353. * Used to provide dependencies that cannot be easily expressed as bindings.
  3354. */
  3355. interface DependencyProvider {
  3356. getDependency(injector: Injector, binding: ResolvedBinding, dependency: Dependency): any;
  3357. }
  3358. enum Visibility {
  3359. Public,
  3360. Private,
  3361. PublicAndPrivate
  3362. }
  3363. const UNDEFINED : Object ;
  3364. /**
  3365. * Describes how_ the {@link Injector} should instantiate a given token.
  3366. *
  3367. * See {@link bind}.
  3368. *
  3369. * ## Example
  3370. *
  3371. * ```javascript
  3372. * var injector = Injector.resolveAndCreate([
  3373. * new Binding(String, { toValue: 'Hello' })
  3374. * ]);
  3375. *
  3376. * expect(injector.get(String)).toEqual('Hello');
  3377. * ```
  3378. */
  3379. class Binding {
  3380. /**
  3381. * Token used when retrieving this binding. Usually the `Type`.
  3382. */
  3383. token: any;
  3384. /**
  3385. * Binds an interface to an implementation / subclass.
  3386. *
  3387. * ## Example
  3388. *
  3389. * Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy
  3390. * comparison.
  3391. *
  3392. * ```javascript
  3393. *
  3394. * class Vehicle {}
  3395. *
  3396. * class Car extends Vehicle {}
  3397. *
  3398. * var injectorClass = Injector.resolveAndCreate([
  3399. * Car,
  3400. * new Binding(Vehicle, { toClass: Car })
  3401. * ]);
  3402. * var injectorAlias = Injector.resolveAndCreate([
  3403. * Car,
  3404. * new Binding(Vehicle, { toAlias: Car })
  3405. * ]);
  3406. *
  3407. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  3408. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  3409. *
  3410. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  3411. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  3412. * ```
  3413. */
  3414. toClass: Type;
  3415. /**
  3416. * Binds a key to a value.
  3417. *
  3418. * ## Example
  3419. *
  3420. * ```javascript
  3421. * var injector = Injector.resolveAndCreate([
  3422. * new Binding(String, { toValue: 'Hello' })
  3423. * ]);
  3424. *
  3425. * expect(injector.get(String)).toEqual('Hello');
  3426. * ```
  3427. */
  3428. toValue: any;
  3429. /**
  3430. * Binds a key to the alias for an existing key.
  3431. *
  3432. * An alias means that {@link Injector} returns the same instance as if the alias token was used.
  3433. * This is in contrast to `toClass` where a separate instance of `toClass` is returned.
  3434. *
  3435. * ## Example
  3436. *
  3437. * Becuse `toAlias` and `toClass` are often confused the example contains both use cases for easy
  3438. * comparison.
  3439. *
  3440. * ```javascript
  3441. *
  3442. * class Vehicle {}
  3443. *
  3444. * class Car extends Vehicle {}
  3445. *
  3446. * var injectorAlias = Injector.resolveAndCreate([
  3447. * Car,
  3448. * new Binding(Vehicle, { toAlias: Car })
  3449. * ]);
  3450. * var injectorClass = Injector.resolveAndCreate([
  3451. * Car,
  3452. * new Binding(Vehicle, { toClass: Car })
  3453. * ]);
  3454. *
  3455. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  3456. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  3457. *
  3458. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  3459. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  3460. * ```
  3461. */
  3462. toAlias: any;
  3463. /**
  3464. * Binds a key to a function which computes the value.
  3465. *
  3466. * ## Example
  3467. *
  3468. * ```javascript
  3469. * var injector = Injector.resolveAndCreate([
  3470. * new Binding(Number, { toFactory: () => { return 1+2; }}),
  3471. * new Binding(String, { toFactory: (value) => { return "Value: " + value; },
  3472. * dependencies: [Number] })
  3473. * ]);
  3474. *
  3475. * expect(injector.get(Number)).toEqual(3);
  3476. * expect(injector.get(String)).toEqual('Value: 3');
  3477. * ```
  3478. */
  3479. toFactory: Function;
  3480. /**
  3481. * Used in conjunction with `toFactory` and specifies a set of dependencies
  3482. * (as `token`s) which should be injected into the factory function.
  3483. *
  3484. * ## Example
  3485. *
  3486. * ```javascript
  3487. * var injector = Injector.resolveAndCreate([
  3488. * new Binding(Number, { toFactory: () => { return 1+2; }}),
  3489. * new Binding(String, { toFactory: (value) => { return "Value: " + value; },
  3490. * dependencies: [Number] })
  3491. * ]);
  3492. *
  3493. * expect(injector.get(Number)).toEqual(3);
  3494. * expect(injector.get(String)).toEqual('Value: 3');
  3495. * ```
  3496. */
  3497. dependencies: any[];
  3498. /**
  3499. * Converts the {@link Binding} into {@link ResolvedBinding}.
  3500. *
  3501. * {@link Injector} internally only uses {@link ResolvedBinding}, {@link Binding} contains
  3502. * convenience binding syntax.
  3503. */
  3504. resolve(): ResolvedBinding;
  3505. }
  3506. /**
  3507. * Helper class for the {@link bind} function.
  3508. */
  3509. class BindingBuilder {
  3510. token: any;
  3511. /**
  3512. * Binds an interface to an implementation / subclass.
  3513. *
  3514. * ## Example
  3515. *
  3516. * Because `toAlias` and `toClass` are often confused, the example contains both use cases for
  3517. * easy comparison.
  3518. *
  3519. * ```javascript
  3520. *
  3521. * class Vehicle {}
  3522. *
  3523. * class Car extends Vehicle {}
  3524. *
  3525. * var injectorClass = Injector.resolveAndCreate([
  3526. * Car,
  3527. * bind(Vehicle).toClass(Car)
  3528. * ]);
  3529. * var injectorAlias = Injector.resolveAndCreate([
  3530. * Car,
  3531. * bind(Vehicle).toAlias(Car)
  3532. * ]);
  3533. *
  3534. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  3535. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  3536. *
  3537. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  3538. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  3539. * ```
  3540. */
  3541. toClass(type: Type): Binding;
  3542. /**
  3543. * Binds a key to a value.
  3544. *
  3545. * ## Example
  3546. *
  3547. * ```javascript
  3548. * var injector = Injector.resolveAndCreate([
  3549. * bind(String).toValue('Hello')
  3550. * ]);
  3551. *
  3552. * expect(injector.get(String)).toEqual('Hello');
  3553. * ```
  3554. */
  3555. toValue(value: any): Binding;
  3556. /**
  3557. * Binds a key to the alias for an existing key.
  3558. *
  3559. * An alias means that we will return the same instance as if the alias token was used. (This is
  3560. * in contrast to `toClass` where a separate instance of `toClass` will be returned.)
  3561. *
  3562. * ## Example
  3563. *
  3564. * Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy
  3565. * comparison.
  3566. *
  3567. * ```javascript
  3568. *
  3569. * class Vehicle {}
  3570. *
  3571. * class Car extends Vehicle {}
  3572. *
  3573. * var injectorAlias = Injector.resolveAndCreate([
  3574. * Car,
  3575. * bind(Vehicle).toAlias(Car)
  3576. * ]);
  3577. * var injectorClass = Injector.resolveAndCreate([
  3578. * Car,
  3579. * bind(Vehicle).toClass(Car)
  3580. * ]);
  3581. *
  3582. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  3583. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  3584. *
  3585. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  3586. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  3587. * ```
  3588. */
  3589. toAlias(aliasToken: /*Type*/ any): Binding;
  3590. /**
  3591. * Binds a key to a function which computes the value.
  3592. *
  3593. * ## Example
  3594. *
  3595. * ```javascript
  3596. * var injector = Injector.resolveAndCreate([
  3597. * bind(Number).toFactory(() => { return 1+2; }),
  3598. * bind(String).toFactory((v) => { return "Value: " + v; }, [Number])
  3599. * ]);
  3600. *
  3601. * expect(injector.get(Number)).toEqual(3);
  3602. * expect(injector.get(String)).toEqual('Value: 3');
  3603. * ```
  3604. */
  3605. toFactory(factoryFunction: Function, dependencies?: any[]): Binding;
  3606. }
  3607. /**
  3608. * An internal resolved representation of a {@link Binding} used by the {@link Injector}.
  3609. *
  3610. * A {@link Binding} is resolved when it has a factory function. Binding to a class, alias, or
  3611. * value, are just convenience methods, as {@link Injector} only operates on calling factory
  3612. * functions.
  3613. */
  3614. class ResolvedBinding {
  3615. /**
  3616. * A key, usually a `Type`.
  3617. */
  3618. key: Key;
  3619. /**
  3620. * Factory function which can return an instance of an object represented by a key.
  3621. */
  3622. factory: Function;
  3623. /**
  3624. * Arguments (dependencies) to the `factory` function.
  3625. */
  3626. dependencies: Dependency[];
  3627. }
  3628. /**
  3629. * @private
  3630. */
  3631. class Dependency {
  3632. static fromKey(key: Key): Dependency;
  3633. key: Key;
  3634. optional: boolean;
  3635. lowerBoundVisibility: any;
  3636. upperBoundVisibility: any;
  3637. properties: any[];
  3638. }
  3639. /**
  3640. * Provides an API for imperatively constructing {@link Binding}s.
  3641. *
  3642. * This is only relevant for JavaScript. See {@link BindingBuilder}.
  3643. *
  3644. * ## Example
  3645. *
  3646. * ```javascript
  3647. * bind(MyInterface).toClass(MyClass)
  3648. *
  3649. * ```
  3650. */
  3651. function bind(token: any) : BindingBuilder ;
  3652. /**
  3653. * A unique object used for retrieving items from the {@link Injector}.
  3654. *
  3655. * Keys have:
  3656. * - a system-wide unique `id`.
  3657. * - a `token`, usually the `Type` of the instance.
  3658. *
  3659. * Keys are used internally by the {@link Injector} because their system-wide unique `id`s allow the
  3660. * injector to index in arrays rather than looking up items in maps.
  3661. */
  3662. class Key {
  3663. /**
  3664. * Retrieves a `Key` for a token.
  3665. */
  3666. static get(token: Object): Key;
  3667. /**
  3668. * @returns the number of keys registered in the system.
  3669. */
  3670. static numberOfKeys: number;
  3671. token: Object;
  3672. id: number;
  3673. displayName: string;
  3674. }
  3675. /**
  3676. * @private
  3677. */
  3678. class KeyRegistry {
  3679. get(token: Object): Key;
  3680. numberOfKeys: number;
  3681. }
  3682. /**
  3683. * Type literals is a Dart-only feature. This is here only so we can x-compile
  3684. * to multiple languages.
  3685. */
  3686. class TypeLiteral {
  3687. type: any;
  3688. }
  3689. /**
  3690. * Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the
  3691. * {@link Injector} does not have a {@link Binding} for {@link Key}.
  3692. */
  3693. class NoBindingError extends AbstractBindingError {
  3694. }
  3695. /**
  3696. * Base class for all errors arising from misconfigured bindings.
  3697. */
  3698. class AbstractBindingError extends BaseException {
  3699. name: string;
  3700. message: string;
  3701. keys: Key[];
  3702. injectors: Injector[];
  3703. constructResolvingMessage: Function;
  3704. addKey(injector: Injector, key: Key): void;
  3705. context: any;
  3706. toString(): string;
  3707. }
  3708. /**
  3709. * Thrown when dependencies form a cycle.
  3710. *
  3711. * ## Example:
  3712. *
  3713. * ```javascript
  3714. * class A {
  3715. * constructor(b:B) {}
  3716. * }
  3717. * class B {
  3718. * constructor(a:A) {}
  3719. * }
  3720. * ```
  3721. *
  3722. * Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed.
  3723. */
  3724. class CyclicDependencyError extends AbstractBindingError {
  3725. }
  3726. /**
  3727. * Thrown when a constructing type returns with an Error.
  3728. *
  3729. * The `InstantiationError` class contains the original error plus the dependency graph which caused
  3730. * this object to be instantiated.
  3731. */
  3732. class InstantiationError extends AbstractBindingError {
  3733. causeKey: Key;
  3734. }
  3735. /**
  3736. * Thrown when an object other then {@link Binding} (or `Type`) is passed to {@link Injector}
  3737. * creation.
  3738. */
  3739. class InvalidBindingError extends BaseException {
  3740. message: string;
  3741. toString(): string;
  3742. }
  3743. /**
  3744. * Thrown when the class has no annotation information.
  3745. *
  3746. * Lack of annotation information prevents the {@link Injector} from determining which dependencies
  3747. * need to be injected into the constructor.
  3748. */
  3749. class NoAnnotationError extends BaseException {
  3750. name: string;
  3751. message: string;
  3752. toString(): string;
  3753. }
  3754. /**
  3755. * Thrown when getting an object by index.
  3756. */
  3757. class OutOfBoundsError extends BaseException {
  3758. message: string;
  3759. toString(): string;
  3760. }
  3761. class OpaqueToken {
  3762. toString(): string;
  3763. }
  3764. /**
  3765. * Factory for creating {@link InjectMetadata}.
  3766. */
  3767. interface InjectFactory {
  3768. new(token: any): InjectMetadata;
  3769. (token: any): any;
  3770. }
  3771. /**
  3772. * Factory for creating {@link OptionalMetadata}.
  3773. */
  3774. interface OptionalFactory {
  3775. new(): OptionalMetadata;
  3776. (): any;
  3777. }
  3778. /**
  3779. * Factory for creating {@link InjectableMetadata}.
  3780. */
  3781. interface InjectableFactory {
  3782. new(): InjectableMetadata;
  3783. (): any;
  3784. }
  3785. /**
  3786. * Factory for creating {@link SelfMetadata}.
  3787. */
  3788. interface SelfFactory {
  3789. new(): SelfMetadata;
  3790. (): any;
  3791. }
  3792. /**
  3793. * Factory for creating {@link HostMetadata}.
  3794. */
  3795. interface HostFactory {
  3796. new(): HostMetadata;
  3797. (): any;
  3798. }
  3799. /**
  3800. * Factory for creating {@link SkipSelfMetadata}.
  3801. */
  3802. interface SkipSelfFactory {
  3803. new(): SkipSelfMetadata;
  3804. (): any;
  3805. }
  3806. /**
  3807. * Factory for creating {@link InjectMetadata}.
  3808. */
  3809. var Inject : InjectFactory ;
  3810. /**
  3811. * Factory for creating {@link OptionalMetadata}.
  3812. */
  3813. var Optional : OptionalFactory ;
  3814. /**
  3815. * Factory for creating {@link InjectableMetadata}.
  3816. */
  3817. var Injectable : InjectableFactory ;
  3818. /**
  3819. * Factory for creating {@link SelfMetadata}.
  3820. */
  3821. var Self : SelfFactory ;
  3822. /**
  3823. * Factory for creating {@link HostMetadata}.
  3824. */
  3825. var Host : HostFactory ;
  3826. /**
  3827. * Factory for creating {@link SkipSelfMetadata}.
  3828. */
  3829. var SkipSelf : SkipSelfFactory ;
  3830. /**
  3831. * A collection of the Angular core directives that are likely to be used in each and every Angular
  3832. * application.
  3833. *
  3834. * This collection can be used to quickly enumerate all the built-in directives in the `@View`
  3835. * annotation. For example,
  3836. * instead of writing:
  3837. *
  3838. * ```
  3839. * import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from 'angular2/angular2';
  3840. * import {OtherDirective} from 'myDirectives';
  3841. *
  3842. * @Component({
  3843. * selector: 'my-component'
  3844. * })
  3845. * @View({
  3846. * templateUrl: 'myComponent.html',
  3847. * directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, OtherDirective]
  3848. * })
  3849. * export class MyComponent {
  3850. * ...
  3851. * }
  3852. * ```
  3853. * one could import all the core directives at once:
  3854. *
  3855. * ```
  3856. * import {CORE_DIRECTIVES} from 'angular2/angular2';
  3857. * import {OtherDirective} from 'myDirectives';
  3858. *
  3859. * @Component({
  3860. * selector: 'my-component'
  3861. * })
  3862. * @View({
  3863. * templateUrl: 'myComponent.html',
  3864. * directives: [CORE_DIRECTIVES, OtherDirective]
  3865. * })
  3866. * export class MyComponent {
  3867. * ...
  3868. * }
  3869. * ```
  3870. */
  3871. const CORE_DIRECTIVES : Type[] ;
  3872. /**
  3873. * Adds and removes CSS classes based on an {expression} value.
  3874. *
  3875. * The result of expression is used to add and remove CSS classes using the following logic,
  3876. * based on expression's value type:
  3877. * - {string} - all the CSS classes (space - separated) are added
  3878. * - {Array} - all the CSS classes (Array elements) are added
  3879. * - {Object} - each key corresponds to a CSS class name while values
  3880. * are interpreted as {boolean} expression. If a given expression
  3881. * evaluates to {true} a corresponding CSS class is added - otherwise
  3882. * it is removed.
  3883. *
  3884. * # Example:
  3885. *
  3886. * ```
  3887. * <div class="message" [ng-class]="{error: errorCount > 0}">
  3888. * Please check errors.
  3889. * </div>
  3890. * ```
  3891. */
  3892. class NgClass {
  3893. initialClasses: any;
  3894. rawClass: any;
  3895. doCheck(): void;
  3896. onDestroy(): void;
  3897. }
  3898. /**
  3899. * The `NgFor` directive instantiates a template once per item from an iterable. The context for
  3900. * each instantiated template inherits from the outer context with the given loop variable set
  3901. * to the current item from the iterable.
  3902. *
  3903. * It is possible to alias the `index` to a local variable that will be set to the current loop
  3904. * iteration in the template context.
  3905. *
  3906. * When the contents of the iterator changes, `NgFor` makes the corresponding changes to the DOM:
  3907. *
  3908. * * When an item is added, a new instance of the template is added to the DOM.
  3909. * * When an item is removed, its template instance is removed from the DOM.
  3910. * * When items are reordered, their respective templates are reordered in the DOM.
  3911. *
  3912. * # Example
  3913. *
  3914. * ```
  3915. * <ul>
  3916. * <li *ng-for="#error of errors; #i = index">
  3917. * Error {{i}} of {{errors.length}}: {{error.message}}
  3918. * </li>
  3919. * </ul>
  3920. * ```
  3921. *
  3922. * # Syntax
  3923. *
  3924. * - `<li *ng-for="#item of items; #i = index">...</li>`
  3925. * - `<li template="ng-for #item of items; #i = index">...</li>`
  3926. * - `<template ng-for #item [ng-for-of]="items" #i="index"><li>...</li></template>`
  3927. */
  3928. class NgFor {
  3929. static bulkRemove(tuples: RecordViewTuple[], viewContainer: ViewContainerRef): RecordViewTuple[];
  3930. static bulkInsert(tuples: RecordViewTuple[], viewContainer: ViewContainerRef, templateRef: TemplateRef): RecordViewTuple[];
  3931. viewContainer: ViewContainerRef;
  3932. templateRef: TemplateRef;
  3933. iterableDiffers: IterableDiffers;
  3934. cdr: ChangeDetectorRef;
  3935. ngForOf: any;
  3936. doCheck(): void;
  3937. }
  3938. class RecordViewTuple {
  3939. view: ViewRef;
  3940. record: any;
  3941. }
  3942. /**
  3943. * Removes or recreates a portion of the DOM tree based on an {expression}.
  3944. *
  3945. * If the expression assigned to `ng-if` evaluates to a false value then the element
  3946. * is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.
  3947. *
  3948. * # Example:
  3949. *
  3950. * ```
  3951. * <div *ng-if="errorCount > 0" class="error">
  3952. * <!-- Error message displayed when the errorCount property on the current context is greater
  3953. * than 0. -->
  3954. * {{errorCount}} errors detected
  3955. * </div>
  3956. * ```
  3957. *
  3958. * # Syntax
  3959. *
  3960. * - `<div *ng-if="condition">...</div>`
  3961. * - `<div template="ng-if condition">...</div>`
  3962. * - `<template [ng-if]="condition"><div>...</div></template>`
  3963. */
  3964. class NgIf {
  3965. ngIf: any;
  3966. }
  3967. /**
  3968. * The `NgNonBindable` directive tells Angular not to compile or bind the contents of the current
  3969. * DOM element. This is useful if the element contains what appears to be Angular directives and
  3970. * bindings but which should be ignored by Angular. This could be the case if you have a site that
  3971. * displays snippets of code, for instance.
  3972. *
  3973. * Example:
  3974. *
  3975. * ```
  3976. * <div>Normal: {{1 + 2}}</div> // output "Normal: 3"
  3977. * <div ng-non-bindable>Ignored: {{1 + 2}}</div> // output "Ignored: {{1 + 2}}"
  3978. * ```
  3979. */
  3980. class NgNonBindable {
  3981. }
  3982. /**
  3983. * Adds or removes styles based on an {expression}.
  3984. *
  3985. * When the expression assigned to `ng-style` evaluates to an object, the corresponding element
  3986. * styles are updated. Style names to update are taken from the object keys and values - from the
  3987. * corresponding object values.
  3988. *
  3989. * # Example:
  3990. *
  3991. * ```
  3992. * <div [ng-style]="{'text-align': alignExp}"></div>
  3993. * ```
  3994. *
  3995. * In the above example the `text-align` style will be updated based on the `alignExp` value
  3996. * changes.
  3997. *
  3998. * # Syntax
  3999. *
  4000. * - `<div [ng-style]="{'text-align': alignExp}"></div>`
  4001. * - `<div [ng-style]="styleExp"></div>`
  4002. */
  4003. class NgStyle {
  4004. rawStyle: any;
  4005. doCheck(): void;
  4006. }
  4007. class SwitchView {
  4008. create(): void;
  4009. destroy(): void;
  4010. }
  4011. /**
  4012. * The `NgSwitch` directive is used to conditionally swap DOM structure on your template based on a
  4013. * scope expression.
  4014. * Elements within `NgSwitch` but without `NgSwitchWhen` or `NgSwitchDefault` directives will be
  4015. * preserved at the location as specified in the template.
  4016. *
  4017. * `NgSwitch` simply chooses nested elements and makes them visible based on which element matches
  4018. * the value obtained from the evaluated expression. In other words, you define a container element
  4019. * (where you place the directive), place an expression on the **`[ng-switch]="..."` attribute**),
  4020. * define any inner elements inside of the directive and place a `[ng-switch-when]` attribute per
  4021. * element.
  4022. * The when attribute is used to inform NgSwitch which element to display when the expression is
  4023. * evaluated. If a matching expression is not found via a when attribute then an element with the
  4024. * default attribute is displayed.
  4025. *
  4026. * # Example:
  4027. *
  4028. * ```
  4029. * <ANY [ng-switch]="expression">
  4030. * <template [ng-switch-when]="whenExpression1">...</template>
  4031. * <template [ng-switch-when]="whenExpression1">...</template>
  4032. * <template ng-switch-default>...</template>
  4033. * </ANY>
  4034. * ```
  4035. */
  4036. class NgSwitch {
  4037. ngSwitch: any;
  4038. }
  4039. /**
  4040. * Defines a case statement as an expression.
  4041. *
  4042. * If multiple `NgSwitchWhen` match the `NgSwitch` value, all of them are displayed.
  4043. *
  4044. * Example:
  4045. *
  4046. * ```
  4047. * // match against a context variable
  4048. * <template [ng-switch-when]="contextVariable">...</template>
  4049. *
  4050. * // match against a constant string
  4051. * <template ng-switch-when="stringValue">...</template>
  4052. * ```
  4053. */
  4054. class NgSwitchWhen {
  4055. ngSwitchWhen: any;
  4056. }
  4057. /**
  4058. * Defines a default case statement.
  4059. *
  4060. * Default case statements are displayed when no `NgSwitchWhen` match the `ng-switch` value.
  4061. *
  4062. * Example:
  4063. *
  4064. * ```
  4065. * <template ng-switch-default>...</template>
  4066. * ```
  4067. */
  4068. class NgSwitchDefault {
  4069. }
  4070. /**
  4071. * Omitting from external API doc as this is really an abstract internal concept.
  4072. */
  4073. class AbstractControl {
  4074. validator: Function;
  4075. value: any;
  4076. status: string;
  4077. valid: boolean;
  4078. errors: StringMap<string, any>;
  4079. pristine: boolean;
  4080. dirty: boolean;
  4081. touched: boolean;
  4082. untouched: boolean;
  4083. valueChanges: Observable;
  4084. markAsTouched(): void;
  4085. markAsDirty({onlySelf}?: {onlySelf?: boolean}): void;
  4086. setParent(parent: ControlGroup | ControlArray): void;
  4087. updateValidity({onlySelf}?: {onlySelf?: boolean}): void;
  4088. updateValueAndValidity({onlySelf, emitEvent}?: {onlySelf?: boolean, emitEvent?: boolean}): void;
  4089. find(path: Array<string | number>| string): AbstractControl;
  4090. getError(errorCode: string, path?: string[]): any;
  4091. hasError(errorCode: string, path?: string[]): boolean;
  4092. }
  4093. /**
  4094. * Defines a part of a form that cannot be divided into other controls.
  4095. *
  4096. * `Control` is one of the three fundamental building blocks used to define forms in Angular, along
  4097. * with
  4098. * {@link ControlGroup} and {@link ControlArray}.
  4099. */
  4100. class Control extends AbstractControl {
  4101. updateValue(value: any, {onlySelf, emitEvent, emitModelToViewChange}?:
  4102. {onlySelf?: boolean, emitEvent?: boolean, emitModelToViewChange?: boolean}): void;
  4103. registerOnChange(fn: Function): void;
  4104. }
  4105. /**
  4106. * Defines a part of a form, of fixed length, that can contain other controls.
  4107. *
  4108. * A ControlGroup aggregates the values and errors of each {@link Control} in the group. Thus, if
  4109. * one of the controls
  4110. * in a group is invalid, the entire group is invalid. Similarly, if a control changes its value,
  4111. * the entire group
  4112. * changes as well.
  4113. *
  4114. * `ControlGroup` is one of the three fundamental building blocks used to define forms in Angular,
  4115. * along with
  4116. * {@link Control} and {@link ControlArray}. {@link ControlArray} can also contain other controls,
  4117. * but is of variable
  4118. * length.
  4119. */
  4120. class ControlGroup extends AbstractControl {
  4121. controls: StringMap<string, AbstractControl>;
  4122. addControl(name: string, c: AbstractControl): void;
  4123. removeControl(name: string): void;
  4124. include(controlName: string): void;
  4125. exclude(controlName: string): void;
  4126. contains(controlName: string): boolean;
  4127. }
  4128. /**
  4129. * Defines a part of a form, of variable length, that can contain other controls.
  4130. *
  4131. * A `ControlArray` aggregates the values and errors of each {@link Control} in the group. Thus, if
  4132. * one of the controls
  4133. * in a group is invalid, the entire group is invalid. Similarly, if a control changes its value,
  4134. * the entire group
  4135. * changes as well.
  4136. *
  4137. * `ControlArray` is one of the three fundamental building blocks used to define forms in Angular,
  4138. * along with {@link Control} and {@link ControlGroup}. {@link ControlGroup} can also contain
  4139. * other controls, but is of fixed length.
  4140. */
  4141. class ControlArray extends AbstractControl {
  4142. controls: AbstractControl[];
  4143. at(index: number): AbstractControl;
  4144. push(control: AbstractControl): void;
  4145. insert(index: number, control: AbstractControl): void;
  4146. removeAt(index: number): void;
  4147. length: number;
  4148. }
  4149. class AbstractControlDirective {
  4150. control: AbstractControl;
  4151. value: any;
  4152. valid: boolean;
  4153. errors: StringMap<string, any>;
  4154. pristine: boolean;
  4155. dirty: boolean;
  4156. touched: boolean;
  4157. untouched: boolean;
  4158. }
  4159. /**
  4160. * An interface that {@link NgFormModel} and {@link NgForm} implement.
  4161. *
  4162. * Only used by the forms module.
  4163. */
  4164. interface Form {
  4165. addControl(dir: NgControl): void;
  4166. removeControl(dir: NgControl): void;
  4167. getControl(dir: NgControl): Control;
  4168. addControlGroup(dir: NgControlGroup): void;
  4169. removeControlGroup(dir: NgControlGroup): void;
  4170. getControlGroup(dir: NgControlGroup): ControlGroup;
  4171. updateModel(dir: NgControl, value: any): void;
  4172. }
  4173. /**
  4174. * A directive that contains a group of [NgControl].
  4175. *
  4176. * Only used by the forms module.
  4177. */
  4178. class ControlContainer extends AbstractControlDirective {
  4179. name: string;
  4180. formDirective: Form;
  4181. path: string[];
  4182. }
  4183. /**
  4184. * Creates and binds a control with a specified name to a DOM element.
  4185. *
  4186. * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}.
  4187. *
  4188. * # Example
  4189. *
  4190. * In this example, we create the login and password controls.
  4191. * We can work with each control separately: check its validity, get its value, listen to its
  4192. * changes.
  4193. *
  4194. * ```
  4195. * @Component({selector: "login-comp"})
  4196. * @View({
  4197. * directives: [FORM_DIRECTIVES],
  4198. * template: `
  4199. * <form #f="form" (submit)='onLogIn(f.value)'>
  4200. * Login <input type='text' ng-control='login' #l="form">
  4201. * <div *ng-if="!l.valid">Login is invalid</div>
  4202. *
  4203. * Password <input type='password' ng-control='password'>
  4204. *
  4205. * <button type='submit'>Log in!</button>
  4206. * </form>
  4207. * `})
  4208. * class LoginComp {
  4209. * onLogIn(value) {
  4210. * // value === {login: 'some login', password: 'some password'}
  4211. * }
  4212. * }
  4213. * ```
  4214. *
  4215. * We can also use ng-model to bind a domain model to the form.
  4216. *
  4217. * ```
  4218. * @Component({selector: "login-comp"})
  4219. * @View({
  4220. * directives: [FORM_DIRECTIVES],
  4221. * template: `
  4222. * <form (submit)='onLogIn()'>
  4223. * Login <input type='text' ng-control='login' [(ng-model)]="credentials.login">
  4224. * Password <input type='password' ng-control='password'
  4225. * [(ng-model)]="credentials.password">
  4226. * <button type='submit'>Log in!</button>
  4227. * </form>
  4228. * `})
  4229. * class LoginComp {
  4230. * credentials: {login:string, password:string};
  4231. *
  4232. * onLogIn() {
  4233. * // this.credentials.login === "some login"
  4234. * // this.credentials.password === "some password"
  4235. * }
  4236. * }
  4237. * ```
  4238. */
  4239. class NgControlName extends NgControl {
  4240. update: any;
  4241. model: any;
  4242. viewModel: any;
  4243. ngValidators: QueryList<NgValidator>;
  4244. onChanges(c: StringMap<string, any>): void;
  4245. onDestroy(): void;
  4246. viewToModelUpdate(newValue: any): void;
  4247. path: string[];
  4248. formDirective: any;
  4249. control: Control;
  4250. validator: Function;
  4251. }
  4252. /**
  4253. * Binds an existing control to a DOM element.
  4254. *
  4255. * # Example
  4256. *
  4257. * In this example, we bind the control to an input element. When the value of the input element
  4258. * changes, the value of
  4259. * the control will reflect that change. Likewise, if the value of the control changes, the input
  4260. * element reflects that
  4261. * change.
  4262. *
  4263. * ```
  4264. * @Component({selector: "login-comp"})
  4265. * @View({
  4266. * directives: [FORM_DIRECTIVES],
  4267. * template: "<input type='text' [ng-form-control]='loginControl'>"
  4268. * })
  4269. * class LoginComp {
  4270. * loginControl:Control;
  4271. *
  4272. * constructor() {
  4273. * this.loginControl = new Control('');
  4274. * }
  4275. * }
  4276. *
  4277. * ```
  4278. *
  4279. * We can also use ng-model to bind a domain model to the form.
  4280. *
  4281. * ```
  4282. * @Component({selector: "login-comp"})
  4283. * @View({
  4284. * directives: [FORM_DIRECTIVES],
  4285. * template: "<input type='text' [ng-form-control]='loginControl' [(ng-model)]='login'>"
  4286. * })
  4287. * class LoginComp {
  4288. * loginControl:Control;
  4289. * login:string;
  4290. *
  4291. * constructor() {
  4292. * this.loginControl = new Control('');
  4293. * }
  4294. * }
  4295. * ```
  4296. */
  4297. class NgFormControl extends NgControl {
  4298. form: Control;
  4299. update: any;
  4300. model: any;
  4301. viewModel: any;
  4302. ngValidators: QueryList<NgValidator>;
  4303. onChanges(c: StringMap<string, any>): void;
  4304. path: string[];
  4305. control: Control;
  4306. validator: Function;
  4307. viewToModelUpdate(newValue: any): void;
  4308. }
  4309. /**
  4310. * Binds a domain model to the form.
  4311. *
  4312. * # Example
  4313. * ```
  4314. * @Component({selector: "search-comp"})
  4315. * @View({
  4316. * directives: [FORM_DIRECTIVES],
  4317. * template: `
  4318. * <input type='text' [(ng-model)]="searchQuery">
  4319. * `})
  4320. * class SearchComp {
  4321. * searchQuery: string;
  4322. * }
  4323. * ```
  4324. */
  4325. class NgModel extends NgControl {
  4326. update: any;
  4327. model: any;
  4328. viewModel: any;
  4329. ngValidators: QueryList<NgValidator>;
  4330. onChanges(c: StringMap<string, any>): void;
  4331. control: Control;
  4332. path: string[];
  4333. validator: Function;
  4334. viewToModelUpdate(newValue: any): void;
  4335. }
  4336. /**
  4337. * An abstract class that all control directive extend.
  4338. *
  4339. * It binds a {@link Control} object to a DOM element.
  4340. */
  4341. class NgControl extends AbstractControlDirective {
  4342. name: string;
  4343. valueAccessor: ControlValueAccessor;
  4344. validator: Function;
  4345. path: string[];
  4346. viewToModelUpdate(newValue: any): void;
  4347. }
  4348. /**
  4349. * Creates and binds a control group to a DOM element.
  4350. *
  4351. * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}.
  4352. *
  4353. * # Example
  4354. *
  4355. * In this example, we create the credentials and personal control groups.
  4356. * We can work with each group separately: check its validity, get its value, listen to its changes.
  4357. *
  4358. * ```
  4359. * @Component({selector: "signup-comp"})
  4360. * @View({
  4361. * directives: [FORM_DIRECTIVES],
  4362. * template: `
  4363. * <form #f="form" (submit)='onSignUp(f.value)'>
  4364. * <div ng-control-group='credentials' #credentials="form">
  4365. * Login <input type='text' ng-control='login'>
  4366. * Password <input type='password' ng-control='password'>
  4367. * </div>
  4368. * <div *ng-if="!credentials.valid">Credentials are invalid</div>
  4369. *
  4370. * <div ng-control-group='personal'>
  4371. * Name <input type='text' ng-control='name'>
  4372. * </div>
  4373. * <button type='submit'>Sign Up!</button>
  4374. * </form>
  4375. * `})
  4376. * class SignupComp {
  4377. * onSignUp(value) {
  4378. * // value === {personal: {name: 'some name'},
  4379. * // credentials: {login: 'some login', password: 'some password'}}
  4380. * }
  4381. * }
  4382. *
  4383. * ```
  4384. */
  4385. class NgControlGroup extends ControlContainer {
  4386. onInit(): void;
  4387. onDestroy(): void;
  4388. control: ControlGroup;
  4389. path: string[];
  4390. formDirective: Form;
  4391. }
  4392. /**
  4393. * Binds an existing control group to a DOM element.
  4394. *
  4395. * # Example
  4396. *
  4397. * In this example, we bind the control group to the form element, and we bind the login and
  4398. * password controls to the
  4399. * login and password elements.
  4400. *
  4401. * ```
  4402. * @Component({selector: "login-comp"})
  4403. * @View({
  4404. * directives: [FORM_DIRECTIVES],
  4405. * template: "<form [ng-form-model]='loginForm'>" +
  4406. * "Login <input type='text' ng-control='login'>" +
  4407. * "Password <input type='password' ng-control='password'>" +
  4408. * "<button (click)="onLogin()">Login</button>" +
  4409. * "</form>"
  4410. * })
  4411. * class LoginComp {
  4412. * loginForm:ControlGroup;
  4413. *
  4414. * constructor() {
  4415. * this.loginForm = new ControlGroup({
  4416. * login: new Control(""),
  4417. * password: new Control("")
  4418. * });
  4419. * }
  4420. *
  4421. * onLogin() {
  4422. * // this.loginForm.value
  4423. * }
  4424. * }
  4425. *
  4426. * ```
  4427. *
  4428. * We can also use ng-model to bind a domain model to the form.
  4429. *
  4430. * ```
  4431. * @Component({selector: "login-comp"})
  4432. * @View({
  4433. * directives: [FORM_DIRECTIVES],
  4434. * template: "<form [ng-form-model]='loginForm'>" +
  4435. * "Login <input type='text' ng-control='login' [(ng-model)]='login'>" +
  4436. * "Password <input type='password' ng-control='password' [(ng-model)]='password'>" +
  4437. * "<button (click)="onLogin()">Login</button>" +
  4438. * "</form>"
  4439. * })
  4440. * class LoginComp {
  4441. * credentials:{login:string, password:string}
  4442. * loginForm:ControlGroup;
  4443. *
  4444. * constructor() {
  4445. * this.loginForm = new ControlGroup({
  4446. * login: new Control(""),
  4447. * password: new Control("")
  4448. * });
  4449. * }
  4450. *
  4451. * onLogin() {
  4452. * // this.credentials.login === 'some login'
  4453. * // this.credentials.password === 'some password'
  4454. * }
  4455. * }
  4456. * ```
  4457. */
  4458. class NgFormModel extends ControlContainer implements Form {
  4459. form: ControlGroup;
  4460. directives: NgControl[];
  4461. ngSubmit: any;
  4462. onChanges(_: any): void;
  4463. formDirective: Form;
  4464. control: ControlGroup;
  4465. path: string[];
  4466. addControl(dir: NgControl): void;
  4467. getControl(dir: NgControl): Control;
  4468. removeControl(dir: NgControl): void;
  4469. addControlGroup(dir: NgControlGroup): void;
  4470. removeControlGroup(dir: NgControlGroup): void;
  4471. getControlGroup(dir: NgControlGroup): ControlGroup;
  4472. updateModel(dir: NgControl, value: any): void;
  4473. onSubmit(): boolean;
  4474. }
  4475. /**
  4476. * Creates and binds a form object to a DOM element.
  4477. *
  4478. * # Example
  4479. *
  4480. * ```
  4481. * @Component({selector: "signup-comp"})
  4482. * @View({
  4483. * directives: [FORM_DIRECTIVES],
  4484. * template: `
  4485. * <form #f="form" (submit)='onSignUp(f.value)'>
  4486. * <div ng-control-group='credentials' #credentials="form">
  4487. * Login <input type='text' ng-control='login'>
  4488. * Password <input type='password' ng-control='password'>
  4489. * </div>
  4490. * <div *ng-if="!credentials.valid">Credentials are invalid</div>
  4491. *
  4492. * <div ng-control-group='personal'>
  4493. * Name <input type='text' ng-control='name'>
  4494. * </div>
  4495. * <button type='submit'>Sign Up!</button>
  4496. * </form>
  4497. * `})
  4498. * class SignupComp {
  4499. * onSignUp(value) {
  4500. * // value === {personal: {name: 'some name'},
  4501. * // credentials: {login: 'some login', password: 'some password'}}
  4502. * }
  4503. * }
  4504. *
  4505. * ```
  4506. */
  4507. class NgForm extends ControlContainer implements Form {
  4508. form: ControlGroup;
  4509. ngSubmit: any;
  4510. formDirective: Form;
  4511. control: ControlGroup;
  4512. path: string[];
  4513. controls: StringMap<string, AbstractControl>;
  4514. addControl(dir: NgControl): void;
  4515. getControl(dir: NgControl): Control;
  4516. removeControl(dir: NgControl): void;
  4517. addControlGroup(dir: NgControlGroup): void;
  4518. removeControlGroup(dir: NgControlGroup): void;
  4519. getControlGroup(dir: NgControlGroup): ControlGroup;
  4520. updateModel(dir: NgControl, value: any): void;
  4521. onSubmit(): boolean;
  4522. }
  4523. /**
  4524. * A bridge between a control and a native element.
  4525. *
  4526. * Please see {@link DefaultValueAccessor} for more information.
  4527. */
  4528. interface ControlValueAccessor {
  4529. writeValue(obj: any): void;
  4530. registerOnChange(fn: any): void;
  4531. registerOnTouched(fn: any): void;
  4532. }
  4533. /**
  4534. * The default accessor for writing a value and listening to changes that is used by the
  4535. * {@link NgModel}, {@link NgFormControl}, and {@link NgControlName} directives.
  4536. *
  4537. * # Example
  4538. * ```
  4539. * <input type="text" [(ng-model)]="searchQuery">
  4540. * ```
  4541. */
  4542. class DefaultValueAccessor implements ControlValueAccessor {
  4543. cd: NgControl;
  4544. onChange: any;
  4545. onTouched: any;
  4546. renderer: Renderer;
  4547. elementRef: ElementRef;
  4548. writeValue(value: any): void;
  4549. ngClassUntouched: boolean;
  4550. ngClassTouched: boolean;
  4551. ngClassPristine: boolean;
  4552. ngClassDirty: boolean;
  4553. ngClassValid: boolean;
  4554. ngClassInvalid: boolean;
  4555. registerOnChange(fn: (_: any) => void): void;
  4556. registerOnTouched(fn: () => void): void;
  4557. }
  4558. /**
  4559. * The accessor for writing a value and listening to changes on a checkbox input element.
  4560. *
  4561. * # Example
  4562. * ```
  4563. * <input type="checkbox" [ng-control]="rememberLogin">
  4564. * ```
  4565. */
  4566. class CheckboxControlValueAccessor implements ControlValueAccessor {
  4567. cd: NgControl;
  4568. onChange: any;
  4569. onTouched: any;
  4570. renderer: Renderer;
  4571. elementRef: ElementRef;
  4572. writeValue(value: any): void;
  4573. ngClassUntouched: boolean;
  4574. ngClassTouched: boolean;
  4575. ngClassPristine: boolean;
  4576. ngClassDirty: boolean;
  4577. ngClassValid: boolean;
  4578. ngClassInvalid: boolean;
  4579. registerOnChange(fn: (_: any) => {}): void;
  4580. registerOnTouched(fn: () => {}): void;
  4581. }
  4582. /**
  4583. * Marks <option> as dynamic, so Angular can be notified when options change.
  4584. *
  4585. * #Example:
  4586. *
  4587. * ```
  4588. * <select ng-control="city">
  4589. * <option *ng-for="#c of cities" [value]="c"></option>
  4590. * </select>
  4591. * ```
  4592. */
  4593. class NgSelectOption {
  4594. }
  4595. /**
  4596. * The accessor for writing a value and listening to changes on a select element.
  4597. */
  4598. class SelectControlValueAccessor implements ControlValueAccessor {
  4599. cd: NgControl;
  4600. value: string;
  4601. onChange: any;
  4602. onTouched: any;
  4603. renderer: Renderer;
  4604. elementRef: ElementRef;
  4605. writeValue(value: any): void;
  4606. ngClassUntouched: boolean;
  4607. ngClassTouched: boolean;
  4608. ngClassPristine: boolean;
  4609. ngClassDirty: boolean;
  4610. ngClassValid: boolean;
  4611. ngClassInvalid: boolean;
  4612. registerOnChange(fn: () => any): void;
  4613. registerOnTouched(fn: () => any): void;
  4614. }
  4615. /**
  4616. * A list of all the form directives used as part of a `@View` annotation.
  4617. *
  4618. * This is a shorthand for importing them each individually.
  4619. */
  4620. const FORM_DIRECTIVES : Type[] ;
  4621. /**
  4622. * Provides a set of validators used by form controls.
  4623. *
  4624. * # Example
  4625. *
  4626. * ```
  4627. * var loginControl = new Control("", Validators.required)
  4628. * ```
  4629. */
  4630. class Validators {
  4631. static required(c:Control): StringMap<string, boolean>;
  4632. static nullValidator(c: any): StringMap<string, boolean>;
  4633. static compose(validators: Function[]): Function;
  4634. static group(c:ControlGroup): StringMap<string, boolean>;
  4635. static array(c:ControlArray): StringMap<string, boolean>;
  4636. }
  4637. class NgValidator {
  4638. validator: Function;
  4639. }
  4640. class NgRequiredValidator extends NgValidator {
  4641. validator: Function;
  4642. }
  4643. /**
  4644. * Creates a form object from a user-specified configuration.
  4645. *
  4646. * # Example
  4647. *
  4648. * ```
  4649. * import {Component, View, bootstrap} from 'angular2/angular2';
  4650. * import {FormBuilder, Validators, FORM_DIRECTIVES, ControlGroup} from 'angular2/forms';
  4651. *
  4652. * @Component({
  4653. * selector: 'login-comp',
  4654. * viewBindings: [
  4655. * FormBuilder
  4656. * ]
  4657. * })
  4658. * @View({
  4659. * template: `
  4660. * <form [control-group]="loginForm">
  4661. * Login <input control="login">
  4662. *
  4663. * <div control-group="passwordRetry">
  4664. * Password <input type="password" control="password">
  4665. * Confirm password <input type="password" control="passwordConfirmation">
  4666. * </div>
  4667. * </form>
  4668. * `,
  4669. * directives: [
  4670. * FORM_DIRECTIVES
  4671. * ]
  4672. * })
  4673. * class LoginComp {
  4674. * loginForm: ControlGroup;
  4675. *
  4676. * constructor(builder: FormBuilder) {
  4677. * this.loginForm = builder.group({
  4678. * login: ["", Validators.required],
  4679. *
  4680. * passwordRetry: builder.group({
  4681. * password: ["", Validators.required],
  4682. * passwordConfirmation: ["", Validators.required]
  4683. * })
  4684. * });
  4685. * }
  4686. * }
  4687. *
  4688. * bootstrap(LoginComp)
  4689. * ```
  4690. *
  4691. * This example creates a {@link ControlGroup} that consists of a `login` {@link Control}, and a
  4692. * nested
  4693. * {@link ControlGroup} that defines a `password` and a `passwordConfirmation` {@link Control}:
  4694. *
  4695. * ```
  4696. * var loginForm = builder.group({
  4697. * login: ["", Validators.required],
  4698. *
  4699. * passwordRetry: builder.group({
  4700. * password: ["", Validators.required],
  4701. * passwordConfirmation: ["", Validators.required]
  4702. * })
  4703. * });
  4704. *
  4705. * ```
  4706. */
  4707. class FormBuilder {
  4708. group(controlsConfig: StringMap<string, any>, extra?: StringMap<string, any>): ControlGroup;
  4709. control(value: Object, validator?: Function): Control;
  4710. array(controlsConfig: any[], validator?: Function): ControlArray;
  4711. }
  4712. const FORM_BINDINGS : Type[] ;
  4713. class RenderDirectiveMetadata {
  4714. static DIRECTIVE_TYPE: any;
  4715. static COMPONENT_TYPE: any;
  4716. static create({id, selector, compileChildren, events, host, properties, readAttributes, type,
  4717. callOnDestroy, callOnChanges, callDoCheck, callOnInit, callAfterContentInit,
  4718. callAfterContentChecked, callAfterViewInit, callAfterViewChecked, changeDetection,
  4719. exportAs}: {
  4720. id?: string,
  4721. selector?: string,
  4722. compileChildren?: boolean,
  4723. events?: string[],
  4724. host?: Map<string, string>,
  4725. properties?: string[],
  4726. readAttributes?: string[],
  4727. type?: number,
  4728. callOnDestroy?: boolean,
  4729. callOnChanges?: boolean,
  4730. callDoCheck?: boolean,
  4731. callOnInit?: boolean,
  4732. callAfterContentInit?: boolean,
  4733. callAfterContentChecked?: boolean,
  4734. callAfterViewInit?: boolean,
  4735. callAfterViewChecked?: boolean,
  4736. changeDetection?: ChangeDetectionStrategy,
  4737. exportAs?: string
  4738. }): RenderDirectiveMetadata;
  4739. id: any;
  4740. selector: string;
  4741. compileChildren: boolean;
  4742. events: string[];
  4743. properties: string[];
  4744. readAttributes: string[];
  4745. type: number;
  4746. callOnDestroy: boolean;
  4747. callOnChanges: boolean;
  4748. callDoCheck: boolean;
  4749. callOnInit: boolean;
  4750. callAfterContentInit: boolean;
  4751. callAfterContentChecked: boolean;
  4752. callAfterViewInit: boolean;
  4753. callAfterViewChecked: boolean;
  4754. changeDetection: ChangeDetectionStrategy;
  4755. exportAs: string;
  4756. hostListeners: Map<string, string>;
  4757. hostProperties: Map<string, string>;
  4758. hostAttributes: Map<string, string>;
  4759. }
  4760. class DomRenderer extends Renderer {
  4761. createRootHostView(hostProtoViewRef: RenderProtoViewRef, fragmentCount: number, hostElementSelector: string): RenderViewWithFragments;
  4762. createView(protoViewRef: RenderProtoViewRef, fragmentCount: number): RenderViewWithFragments;
  4763. destroyView(viewRef: RenderViewRef): void;
  4764. getNativeElementSync(location: RenderElementRef): any;
  4765. getRootNodes(fragment: RenderFragmentRef): Node[];
  4766. attachFragmentAfterFragment(previousFragmentRef: RenderFragmentRef, fragmentRef: RenderFragmentRef): void;
  4767. attachFragmentAfterElement(elementRef: RenderElementRef, fragmentRef: RenderFragmentRef): void;
  4768. detachFragment(fragmentRef: RenderFragmentRef): void;
  4769. hydrateView(viewRef: RenderViewRef): void;
  4770. dehydrateView(viewRef: RenderViewRef): void;
  4771. setElementProperty(location: RenderElementRef, propertyName: string, propertyValue: any): void;
  4772. setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string): void;
  4773. setElementClass(location: RenderElementRef, className: string, isAdd: boolean): void;
  4774. setElementStyle(location: RenderElementRef, styleName: string, styleValue: string): void;
  4775. invokeElementMethod(location: RenderElementRef, methodName: string, args: any[]): void;
  4776. setText(viewRef: RenderViewRef, textNodeIndex: number, text: string): void;
  4777. setEventDispatcher(viewRef: RenderViewRef, dispatcher: any): void;
  4778. }
  4779. /**
  4780. * A dispatcher for all events happening in a view.
  4781. */
  4782. interface RenderEventDispatcher {
  4783. /**
  4784. * Called when an event was triggered for a on-* attribute on an element.
  4785. * @param {Map<string, any>} locals Locals to be used to evaluate the
  4786. * event expressions
  4787. * @return {boolean} False if `preventDefault` should be called on the DOM event.
  4788. */
  4789. dispatchRenderEvent(elementIndex: number, eventName: string, locals: Map<string, any>): boolean;
  4790. }
  4791. class Renderer {
  4792. /**
  4793. * Creates a root host view that includes the given element.
  4794. * Note that the fragmentCount needs to be passed in so that we can create a result
  4795. * synchronously even when dealing with webworkers!
  4796. *
  4797. * @param {RenderProtoViewRef} hostProtoViewRef a RenderProtoViewRef of type
  4798. * ProtoViewDto.HOST_VIEW_TYPE
  4799. * @param {any} hostElementSelector css selector for the host element (will be queried against the
  4800. * main document)
  4801. * @return {RenderViewWithFragments} the created view including fragments
  4802. */
  4803. createRootHostView(hostProtoViewRef: RenderProtoViewRef, fragmentCount: number, hostElementSelector: string): RenderViewWithFragments;
  4804. /**
  4805. * Creates a regular view out of the given ProtoView.
  4806. * Note that the fragmentCount needs to be passed in so that we can create a result
  4807. * synchronously even when dealing with webworkers!
  4808. */
  4809. createView(protoViewRef: RenderProtoViewRef, fragmentCount: number): RenderViewWithFragments;
  4810. /**
  4811. * Destroys the given view after it has been dehydrated and detached
  4812. */
  4813. destroyView(viewRef: RenderViewRef): void;
  4814. /**
  4815. * Attaches a fragment after another fragment.
  4816. */
  4817. attachFragmentAfterFragment(previousFragmentRef: RenderFragmentRef, fragmentRef: RenderFragmentRef): void;
  4818. /**
  4819. * Attaches a fragment after an element.
  4820. */
  4821. attachFragmentAfterElement(elementRef: RenderElementRef, fragmentRef: RenderFragmentRef): void;
  4822. /**
  4823. * Detaches a fragment.
  4824. */
  4825. detachFragment(fragmentRef: RenderFragmentRef): void;
  4826. /**
  4827. * Hydrates a view after it has been attached. Hydration/dehydration is used for reusing views
  4828. * inside of the view pool.
  4829. */
  4830. hydrateView(viewRef: RenderViewRef): void;
  4831. /**
  4832. * Dehydrates a view after it has been attached. Hydration/dehydration is used for reusing views
  4833. * inside of the view pool.
  4834. */
  4835. dehydrateView(viewRef: RenderViewRef): void;
  4836. /**
  4837. * Returns the native element at the given location.
  4838. * Attention: In a WebWorker scenario, this should always return null!
  4839. */
  4840. getNativeElementSync(location: RenderElementRef): any;
  4841. /**
  4842. * Sets a property on an element.
  4843. */
  4844. setElementProperty(location: RenderElementRef, propertyName: string, propertyValue: any): void;
  4845. /**
  4846. * Sets an attribute on an element.
  4847. */
  4848. setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string): void;
  4849. /**
  4850. * Sets a class on an element.
  4851. */
  4852. setElementClass(location: RenderElementRef, className: string, isAdd: boolean): void;
  4853. /**
  4854. * Sets a style on an element.
  4855. */
  4856. setElementStyle(location: RenderElementRef, styleName: string, styleValue: string): void;
  4857. /**
  4858. * Calls a method on an element.
  4859. */
  4860. invokeElementMethod(location: RenderElementRef, methodName: string, args: any[]): void;
  4861. /**
  4862. * Sets the value of a text node.
  4863. */
  4864. setText(viewRef: RenderViewRef, textNodeIndex: number, text: string): void;
  4865. /**
  4866. * Sets the dispatcher for all events of the given view
  4867. */
  4868. setEventDispatcher(viewRef: RenderViewRef, dispatcher: RenderEventDispatcher): void;
  4869. }
  4870. /**
  4871. * Abstract reference to the element which can be marshaled across web-worker boundary.
  4872. *
  4873. * This interface is used by the Renderer API.
  4874. */
  4875. interface RenderElementRef {
  4876. /**
  4877. * Reference to the `RenderViewRef` where the `RenderElementRef` is inside of.
  4878. */
  4879. renderView: RenderViewRef;
  4880. /**
  4881. * Index of the element inside the `RenderViewRef`.
  4882. *
  4883. * This is used internally by the Angular framework to locate elements.
  4884. */
  4885. renderBoundElementIndex: number;
  4886. }
  4887. class RenderViewRef {
  4888. }
  4889. class RenderProtoViewRef {
  4890. }
  4891. class RenderFragmentRef {
  4892. }
  4893. class RenderViewWithFragments {
  4894. viewRef: RenderViewRef;
  4895. fragmentRefs: RenderFragmentRef[];
  4896. }
  4897. class ViewDefinition {
  4898. componentId: string;
  4899. templateAbsUrl: string;
  4900. template: string;
  4901. directives: RenderDirectiveMetadata[];
  4902. styleAbsUrls: string[];
  4903. styles: string[];
  4904. encapsulation: ViewEncapsulation;
  4905. }
  4906. const DOCUMENT : OpaqueToken ;
  4907. /**
  4908. * A unique id (string) for an angular application.
  4909. */
  4910. const APP_ID : OpaqueToken ;
  4911. /**
  4912. * Defines when a compiled template should be stored as a string
  4913. * rather than keeping its Nodes to preserve memory.
  4914. */
  4915. const MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE : OpaqueToken ;
  4916. /**
  4917. * Create trace scope.
  4918. *
  4919. * Scopes must be strictly nested and are analogous to stack frames, but
  4920. * do not have to follow the stack frames. Instead it is recommended that they follow logical
  4921. * nesting. You may want to use
  4922. * [Event
  4923. * Signatures](http://google.github.io/tracing-framework/instrumenting-code.html#custom-events)
  4924. * as they are defined in WTF.
  4925. *
  4926. * Used to mark scope entry. The return value is used to leave the scope.
  4927. *
  4928. * var myScope = wtfCreateScope('MyClass#myMethod(ascii someVal)');
  4929. *
  4930. * someMethod() {
  4931. * var s = myScope('Foo'); // 'Foo' gets stored in tracing UI
  4932. * // DO SOME WORK HERE
  4933. * return wtfLeave(s, 123); // Return value 123
  4934. * }
  4935. *
  4936. * Note, adding try-finally block around the work to ensure that `wtfLeave` gets called can
  4937. * negatively impact the performance of your application. For this reason we recommend that
  4938. * you don't add them to ensure that `wtfLeave` gets called. In production `wtfLeave` is a noop and
  4939. * so try-finally block has no value. When debugging perf issues, skipping `wtfLeave`, do to
  4940. * exception, will produce incorrect trace, but presence of exception signifies logic error which
  4941. * needs to be fixed before the app should be profiled. Add try-finally only when you expect that
  4942. * an exception is expected during normal execution while profiling.
  4943. */
  4944. var wtfCreateScope : WtfScopeFn ;
  4945. /**
  4946. * Used to mark end of Scope.
  4947. *
  4948. * - `scope` to end.
  4949. * - `returnValue` (optional) to be passed to the WTF.
  4950. *
  4951. * Returns the `returnValue for easy chaining.
  4952. */
  4953. var wtfLeave : <T>(scope: any, returnValue?: T) => T ;
  4954. /**
  4955. * Used to mark Async start. Async are similar to scope but they don't have to be strictly nested.
  4956. * The return value is used in the call to [endAsync]. Async ranges only work if WTF has been
  4957. * enabled.
  4958. *
  4959. * someMethod() {
  4960. * var s = wtfStartTimeRange('HTTP:GET', 'some.url');
  4961. * var future = new Future.delay(5).then((_) {
  4962. * wtfEndTimeRange(s);
  4963. * });
  4964. * }
  4965. */
  4966. var wtfStartTimeRange : (rangeType: string, action: string) => any ;
  4967. /**
  4968. * Ends a async time range operation.
  4969. * [range] is the return value from [wtfStartTimeRange] Async ranges only work if WTF has been
  4970. * enabled.
  4971. */
  4972. var wtfEndTimeRange : (range: any) => void ;
  4973. interface WtfScopeFn {
  4974. (arg0?: any, arg1?: any): any;
  4975. }
  4976. var ChangeDetectorRef: InjectableReference;
  4977. var ApplicationRef: InjectableReference;
  4978. var Compiler: InjectableReference;
  4979. var AppViewManager: InjectableReference;
  4980. var ViewRef: InjectableReference;
  4981. var ProtoViewRef: InjectableReference;
  4982. var ViewContainerRef: InjectableReference;
  4983. var ComponentRef: InjectableReference;
  4984. }
  4985. declare module "angular2/angular2" {
  4986. export = ng;
  4987. }
  4988. declare module ngWorker {
  4989. /**
  4990. * Declare reusable UI building blocks for an application.
  4991. *
  4992. * Each Angular component requires a single `@Component` and at least one `@View` annotation. The
  4993. * `@Component`
  4994. * annotation specifies when a component is instantiated, and which properties and hostListeners it
  4995. * binds to.
  4996. *
  4997. * When a component is instantiated, Angular
  4998. * - creates a shadow DOM for the component.
  4999. * - loads the selected template into the shadow DOM.
  5000. * - creates all the injectable objects configured with `bindings` and `viewBindings`.
  5001. *
  5002. * All template expressions and statements are then evaluated against the component instance.
  5003. *
  5004. * For details on the `@View` annotation, see {@link ViewMetadata}.
  5005. *
  5006. * ## Example
  5007. *
  5008. * ```
  5009. * @Component({
  5010. * selector: 'greet'
  5011. * })
  5012. * @View({
  5013. * template: 'Hello {{name}}!'
  5014. * })
  5015. * class Greet {
  5016. * name: string;
  5017. *
  5018. * constructor() {
  5019. * this.name = 'World';
  5020. * }
  5021. * }
  5022. * ```
  5023. */
  5024. class ComponentMetadata extends DirectiveMetadata {
  5025. /**
  5026. * Defines the used change detection strategy.
  5027. *
  5028. * When a component is instantiated, Angular creates a change detector, which is responsible for
  5029. * propagating the component's bindings.
  5030. *
  5031. * The `changeDetection` property defines, whether the change detection will be checked every time
  5032. * or only when the component tells it to do so.
  5033. */
  5034. changeDetection: ChangeDetectionStrategy;
  5035. /**
  5036. * Defines the set of injectable objects that are visible to its view dom children.
  5037. *
  5038. * ## Simple Example
  5039. *
  5040. * Here is an example of a class that can be injected:
  5041. *
  5042. * ```
  5043. * class Greeter {
  5044. * greet(name:string) {
  5045. * return 'Hello ' + name + '!';
  5046. * }
  5047. * }
  5048. *
  5049. * @Directive({
  5050. * selector: 'needs-greeter'
  5051. * })
  5052. * class NeedsGreeter {
  5053. * greeter:Greeter;
  5054. *
  5055. * constructor(greeter:Greeter) {
  5056. * this.greeter = greeter;
  5057. * }
  5058. * }
  5059. *
  5060. * @Component({
  5061. * selector: 'greet',
  5062. * viewBindings: [
  5063. * Greeter
  5064. * ]
  5065. * })
  5066. * @View({
  5067. * template: `<needs-greeter></needs-greeter>`,
  5068. * directives: [NeedsGreeter]
  5069. * })
  5070. * class HelloWorld {
  5071. * }
  5072. *
  5073. * ```
  5074. */
  5075. viewBindings: any[];
  5076. }
  5077. /**
  5078. * Directives allow you to attach behavior to elements in the DOM.
  5079. *
  5080. * {@link DirectiveMetadata}s with an embedded view are called {@link ComponentMetadata}s.
  5081. *
  5082. * A directive consists of a single directive annotation and a controller class. When the
  5083. * directive's `selector` matches
  5084. * elements in the DOM, the following steps occur:
  5085. *
  5086. * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor
  5087. * arguments.
  5088. * 2. Angular instantiates directives for each matched element using `ElementInjector` in a
  5089. * depth-first order,
  5090. * as declared in the HTML.
  5091. *
  5092. * ## Understanding How Injection Works
  5093. *
  5094. * There are three stages of injection resolution.
  5095. * - *Pre-existing Injectors*:
  5096. * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if
  5097. * the dependency was
  5098. * specified as `@Optional`, returns `null`.
  5099. * - The platform injector resolves browser singleton resources, such as: cookies, title,
  5100. * location, and others.
  5101. * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow
  5102. * the same parent-child hierarchy
  5103. * as the component instances in the DOM.
  5104. * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each
  5105. * element has an `ElementInjector`
  5106. * which follow the same parent-child hierarchy as the DOM elements themselves.
  5107. *
  5108. * When a template is instantiated, it also must instantiate the corresponding directives in a
  5109. * depth-first order. The
  5110. * current `ElementInjector` resolves the constructor dependencies for each directive.
  5111. *
  5112. * Angular then resolves dependencies as follows, according to the order in which they appear in the
  5113. * {@link ViewMetadata}:
  5114. *
  5115. * 1. Dependencies on the current element
  5116. * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary
  5117. * 3. Dependencies on component injectors and their parents until it encounters the root component
  5118. * 4. Dependencies on pre-existing injectors
  5119. *
  5120. *
  5121. * The `ElementInjector` can inject other directives, element-specific special objects, or it can
  5122. * delegate to the parent
  5123. * injector.
  5124. *
  5125. * To inject other directives, declare the constructor parameter as:
  5126. * - `directive:DirectiveType`: a directive on the current element only
  5127. * - `@Host() directive:DirectiveType`: any directive that matches the type between the current
  5128. * element and the
  5129. * Shadow DOM root.
  5130. * - `@Query(DirectiveType) query:QueryList<DirectiveType>`: A live collection of direct child
  5131. * directives.
  5132. * - `@QueryDescendants(DirectiveType) query:QueryList<DirectiveType>`: A live collection of any
  5133. * child directives.
  5134. *
  5135. * To inject element-specific special objects, declare the constructor parameter as:
  5136. * - `element: ElementRef` to obtain a reference to logical element in the view.
  5137. * - `viewContainer: ViewContainerRef` to control child template instantiation, for
  5138. * {@link DirectiveMetadata} directives only
  5139. * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way.
  5140. *
  5141. * ## Example
  5142. *
  5143. * The following example demonstrates how dependency injection resolves constructor arguments in
  5144. * practice.
  5145. *
  5146. *
  5147. * Assume this HTML template:
  5148. *
  5149. * ```
  5150. * <div dependency="1">
  5151. * <div dependency="2">
  5152. * <div dependency="3" my-directive>
  5153. * <div dependency="4">
  5154. * <div dependency="5"></div>
  5155. * </div>
  5156. * <div dependency="6"></div>
  5157. * </div>
  5158. * </div>
  5159. * </div>
  5160. * ```
  5161. *
  5162. * With the following `dependency` decorator and `SomeService` injectable class.
  5163. *
  5164. * ```
  5165. * @Injectable()
  5166. * class SomeService {
  5167. * }
  5168. *
  5169. * @Directive({
  5170. * selector: '[dependency]',
  5171. * properties: [
  5172. * 'id: dependency'
  5173. * ]
  5174. * })
  5175. * class Dependency {
  5176. * id:string;
  5177. * }
  5178. * ```
  5179. *
  5180. * Let's step through the different ways in which `MyDirective` could be declared...
  5181. *
  5182. *
  5183. * ### No injection
  5184. *
  5185. * Here the constructor is declared with no arguments, therefore nothing is injected into
  5186. * `MyDirective`.
  5187. *
  5188. * ```
  5189. * @Directive({ selector: '[my-directive]' })
  5190. * class MyDirective {
  5191. * constructor() {
  5192. * }
  5193. * }
  5194. * ```
  5195. *
  5196. * This directive would be instantiated with no dependencies.
  5197. *
  5198. *
  5199. * ### Component-level injection
  5200. *
  5201. * Directives can inject any injectable instance from the closest component injector or any of its
  5202. * parents.
  5203. *
  5204. * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type
  5205. * from the parent
  5206. * component's injector.
  5207. * ```
  5208. * @Directive({ selector: '[my-directive]' })
  5209. * class MyDirective {
  5210. * constructor(someService: SomeService) {
  5211. * }
  5212. * }
  5213. * ```
  5214. *
  5215. * This directive would be instantiated with a dependency on `SomeService`.
  5216. *
  5217. *
  5218. * ### Injecting a directive from the current element
  5219. *
  5220. * Directives can inject other directives declared on the current element.
  5221. *
  5222. * ```
  5223. * @Directive({ selector: '[my-directive]' })
  5224. * class MyDirective {
  5225. * constructor(dependency: Dependency) {
  5226. * expect(dependency.id).toEqual(3);
  5227. * }
  5228. * }
  5229. * ```
  5230. * This directive would be instantiated with `Dependency` declared at the same element, in this case
  5231. * `dependency="3"`.
  5232. *
  5233. * ### Injecting a directive from any ancestor elements
  5234. *
  5235. * Directives can inject other directives declared on any ancestor element (in the current Shadow
  5236. * DOM), i.e. on the current element, the
  5237. * parent element, or its parents.
  5238. * ```
  5239. * @Directive({ selector: '[my-directive]' })
  5240. * class MyDirective {
  5241. * constructor(@Host() dependency: Dependency) {
  5242. * expect(dependency.id).toEqual(2);
  5243. * }
  5244. * }
  5245. * ```
  5246. *
  5247. * `@Host` checks the current element, the parent, as well as its parents recursively. If
  5248. * `dependency="2"` didn't
  5249. * exist on the direct parent, this injection would
  5250. * have returned
  5251. * `dependency="1"`.
  5252. *
  5253. *
  5254. * ### Injecting a live collection of direct child directives
  5255. *
  5256. *
  5257. * A directive can also query for other child directives. Since parent directives are instantiated
  5258. * before child directives, a directive can't simply inject the list of child directives. Instead,
  5259. * the directive injects a {@link QueryList}, which updates its contents as children are added,
  5260. * removed, or moved by a directive that uses a {@link ViewContainerRef} such as a `ng-for`, an
  5261. * `ng-if`, or an `ng-switch`.
  5262. *
  5263. * ```
  5264. * @Directive({ selector: '[my-directive]' })
  5265. * class MyDirective {
  5266. * constructor(@Query(Dependency) dependencies:QueryList<Dependency>) {
  5267. * }
  5268. * }
  5269. * ```
  5270. *
  5271. * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and
  5272. * 6. Here, `Dependency` 5 would not be included, because it is not a direct child.
  5273. *
  5274. * ### Injecting a live collection of descendant directives
  5275. *
  5276. * By passing the descendant flag to `@Query` above, we can include the children of the child
  5277. * elements.
  5278. *
  5279. * ```
  5280. * @Directive({ selector: '[my-directive]' })
  5281. * class MyDirective {
  5282. * constructor(@Query(Dependency, {descendants: true}) dependencies:QueryList<Dependency>) {
  5283. * }
  5284. * }
  5285. * ```
  5286. *
  5287. * This directive would be instantiated with a Query which would contain `Dependency` 4, 5 and 6.
  5288. *
  5289. * ### Optional injection
  5290. *
  5291. * The normal behavior of directives is to return an error when a specified dependency cannot be
  5292. * resolved. If you
  5293. * would like to inject `null` on unresolved dependency instead, you can annotate that dependency
  5294. * with `@Optional()`.
  5295. * This explicitly permits the author of a template to treat some of the surrounding directives as
  5296. * optional.
  5297. *
  5298. * ```
  5299. * @Directive({ selector: '[my-directive]' })
  5300. * class MyDirective {
  5301. * constructor(@Optional() dependency:Dependency) {
  5302. * }
  5303. * }
  5304. * ```
  5305. *
  5306. * This directive would be instantiated with a `Dependency` directive found on the current element.
  5307. * If none can be
  5308. * found, the injector supplies `null` instead of throwing an error.
  5309. *
  5310. * ## Example
  5311. *
  5312. * Here we use a decorator directive to simply define basic tool-tip behavior.
  5313. *
  5314. * ```
  5315. * @Directive({
  5316. * selector: '[tooltip]',
  5317. * properties: [
  5318. * 'text: tooltip'
  5319. * ],
  5320. * host: {
  5321. * '(mouseenter)': 'onMouseEnter()',
  5322. * '(mouseleave)': 'onMouseLeave()'
  5323. * }
  5324. * })
  5325. * class Tooltip{
  5326. * text:string;
  5327. * overlay:Overlay; // NOT YET IMPLEMENTED
  5328. * overlayManager:OverlayManager; // NOT YET IMPLEMENTED
  5329. *
  5330. * constructor(overlayManager:OverlayManager) {
  5331. * this.overlay = overlay;
  5332. * }
  5333. *
  5334. * onMouseEnter() {
  5335. * // exact signature to be determined
  5336. * this.overlay = this.overlayManager.open(text, ...);
  5337. * }
  5338. *
  5339. * onMouseLeave() {
  5340. * this.overlay.close();
  5341. * this.overlay = null;
  5342. * }
  5343. * }
  5344. * ```
  5345. * In our HTML template, we can then add this behavior to a `<div>` or any other element with the
  5346. * `tooltip` selector,
  5347. * like so:
  5348. *
  5349. * ```
  5350. * <div tooltip="some text here"></div>
  5351. * ```
  5352. *
  5353. * Directives can also control the instantiation, destruction, and positioning of inline template
  5354. * elements:
  5355. *
  5356. * A directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at
  5357. * runtime.
  5358. * The {@link ViewContainerRef} is created as a result of `<template>` element, and represents a
  5359. * location in the current view
  5360. * where these actions are performed.
  5361. *
  5362. * Views are always created as children of the current {@link ViewMetadata}, and as siblings of the
  5363. * `<template>` element. Thus a
  5364. * directive in a child view cannot inject the directive that created it.
  5365. *
  5366. * Since directives that create views via ViewContainers are common in Angular, and using the full
  5367. * `<template>` element syntax is wordy, Angular
  5368. * also supports a shorthand notation: `<li *foo="bar">` and `<li template="foo: bar">` are
  5369. * equivalent.
  5370. *
  5371. * Thus,
  5372. *
  5373. * ```
  5374. * <ul>
  5375. * <li *foo="bar" title="text"></li>
  5376. * </ul>
  5377. * ```
  5378. *
  5379. * Expands in use to:
  5380. *
  5381. * ```
  5382. * <ul>
  5383. * <template [foo]="bar">
  5384. * <li title="text"></li>
  5385. * </template>
  5386. * </ul>
  5387. * ```
  5388. *
  5389. * Notice that although the shorthand places `*foo="bar"` within the `<li>` element, the binding for
  5390. * the directive
  5391. * controller is correctly instantiated on the `<template>` element rather than the `<li>` element.
  5392. *
  5393. *
  5394. * ## Example
  5395. *
  5396. * Let's suppose we want to implement the `unless` behavior, to conditionally include a template.
  5397. *
  5398. * Here is a simple directive that triggers on an `unless` selector:
  5399. *
  5400. * ```
  5401. * @Directive({
  5402. * selector: '[unless]',
  5403. * properties: ['unless']
  5404. * })
  5405. * export class Unless {
  5406. * viewContainer: ViewContainerRef;
  5407. * templateRef: TemplateRef;
  5408. * prevCondition: boolean;
  5409. *
  5410. * constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef) {
  5411. * this.viewContainer = viewContainer;
  5412. * this.templateRef = templateRef;
  5413. * this.prevCondition = null;
  5414. * }
  5415. *
  5416. * set unless(newCondition) {
  5417. * if (newCondition && (isBlank(this.prevCondition) || !this.prevCondition)) {
  5418. * this.prevCondition = true;
  5419. * this.viewContainer.clear();
  5420. * } else if (!newCondition && (isBlank(this.prevCondition) || this.prevCondition)) {
  5421. * this.prevCondition = false;
  5422. * this.viewContainer.create(this.templateRef);
  5423. * }
  5424. * }
  5425. * }
  5426. * ```
  5427. *
  5428. * We can then use this `unless` selector in a template:
  5429. * ```
  5430. * <ul>
  5431. * <li *unless="expr"></li>
  5432. * </ul>
  5433. * ```
  5434. *
  5435. * Once the directive instantiates the child view, the shorthand notation for the template expands
  5436. * and the result is:
  5437. *
  5438. * ```
  5439. * <ul>
  5440. * <template [unless]="exp">
  5441. * <li></li>
  5442. * </template>
  5443. * <li></li>
  5444. * </ul>
  5445. * ```
  5446. *
  5447. * Note also that although the `<li></li>` template still exists inside the `<template></template>`,
  5448. * the instantiated
  5449. * view occurs on the second `<li></li>` which is a sibling to the `<template>` element.
  5450. */
  5451. class DirectiveMetadata extends InjectableMetadata {
  5452. /**
  5453. * The CSS selector that triggers the instantiation of a directive.
  5454. *
  5455. * Angular only allows directives to trigger on CSS selectors that do not cross element
  5456. * boundaries.
  5457. *
  5458. * `selector` may be declared as one of the following:
  5459. *
  5460. * - `element-name`: select by element name.
  5461. * - `.class`: select by class name.
  5462. * - `[attribute]`: select by attribute name.
  5463. * - `[attribute=value]`: select by attribute name and value.
  5464. * - `:not(sub_selector)`: select only if the element does not match the `sub_selector`.
  5465. * - `selector1, selector2`: select if either `selector1` or `selector2` matches.
  5466. *
  5467. *
  5468. * ## Example
  5469. *
  5470. * Suppose we have a directive with an `input[type=text]` selector.
  5471. *
  5472. * And the following HTML:
  5473. *
  5474. * ```html
  5475. * <form>
  5476. * <input type="text">
  5477. * <input type="radio">
  5478. * <form>
  5479. * ```
  5480. *
  5481. * The directive would only be instantiated on the `<input type="text">` element.
  5482. */
  5483. selector: string;
  5484. /**
  5485. * Enumerates the set of properties that accept data binding for a directive.
  5486. *
  5487. * The `properties` property defines a set of `directiveProperty` to `bindingProperty`
  5488. * configuration:
  5489. *
  5490. * - `directiveProperty` specifies the component property where the value is written.
  5491. * - `bindingProperty` specifies the DOM property where the value is read from.
  5492. *
  5493. * You can include a {@link PipeMetadata} when specifying a `bindingProperty` to allow for data
  5494. * transformation and structural change detection of the value. These pipes will be evaluated in
  5495. * the context of this component.
  5496. *
  5497. * ## Syntax
  5498. *
  5499. * There is no need to specify both `directiveProperty` and `bindingProperty` when they both have
  5500. * the same value.
  5501. *
  5502. * ```
  5503. * @Directive({
  5504. * properties: [
  5505. * 'propertyName', // shorthand notation for 'propertyName: propertyName'
  5506. * 'directiveProperty1: bindingProperty1',
  5507. * 'directiveProperty2: bindingProperty2 | pipe1 | ...',
  5508. * ...
  5509. * ]
  5510. * }
  5511. * ```
  5512. *
  5513. *
  5514. * ## Basic Property Binding
  5515. *
  5516. * We can easily build a simple `Tooltip` directive that exposes a `tooltip` property, which can
  5517. * be used in templates with standard Angular syntax. For example:
  5518. *
  5519. * ```
  5520. * @Directive({
  5521. * selector: '[tooltip]',
  5522. * properties: [
  5523. * 'text: tooltip'
  5524. * ]
  5525. * })
  5526. * class Tooltip {
  5527. * set text(value: string) {
  5528. * // This will get called every time with the new value when the 'tooltip' property changes
  5529. * }
  5530. * }
  5531. * ```
  5532. *
  5533. * We can then bind to the `tooltip' property as either an expression (`someExpression`) or as a
  5534. * string literal, as shown in the HTML template below:
  5535. *
  5536. * ```html
  5537. * <div [tooltip]="someExpression">...</div>
  5538. * <div tooltip="Some Text">...</div>
  5539. * ```
  5540. *
  5541. * Whenever the `someExpression` expression changes, the `properties` declaration instructs
  5542. * Angular to update the `Tooltip`'s `text` property.
  5543. *
  5544. * ### Bindings With Pipes
  5545. *
  5546. * You can use pipes in bindings, as follows:
  5547. *
  5548. * ```html
  5549. * <div [class-set]="someExpression | somePipe">
  5550. * ```
  5551. */
  5552. properties: string[];
  5553. /**
  5554. * Enumerates the set of emitted events.
  5555. *
  5556. * ## Syntax
  5557. *
  5558. * ```
  5559. * @Component({
  5560. * events: ['statusChange']
  5561. * })
  5562. * class TaskComponent {
  5563. * statusChange: EventEmitter;
  5564. *
  5565. * constructor() {
  5566. * this.statusChange = new EventEmitter();
  5567. * }
  5568. *
  5569. * onComplete() {
  5570. * this.statusChange.next('completed');
  5571. * }
  5572. * }
  5573. * ```
  5574. *
  5575. * Use `propertyName: eventName` when the event emitter property name is different from the name
  5576. * of the emitted event:
  5577. *
  5578. * ```
  5579. * @Component({
  5580. * events: ['status: statusChange']
  5581. * })
  5582. * class TaskComponent {
  5583. * status: EventEmitter;
  5584. *
  5585. * constructor() {
  5586. * this.status = new EventEmitter();
  5587. * }
  5588. *
  5589. * onComplete() {
  5590. * this.status.next('completed');
  5591. * }
  5592. * }
  5593. * ```
  5594. */
  5595. events: string[];
  5596. /**
  5597. * Specifiy the events, actions, properties and attributes related to the host element.
  5598. *
  5599. * ## Events
  5600. *
  5601. * Specifies which DOM hostListeners a directive listens to via a set of `(event)` to `method`
  5602. * key-value pairs:
  5603. *
  5604. * - `event1`: the DOM event that the directive listens to.
  5605. * - `statement`: the statement to execute when the event occurs.
  5606. * If the evalutation of the statement returns `false`, then `preventDefault`is applied on the DOM
  5607. * event.
  5608. *
  5609. * To listen to global events, a target must be added to the event name.
  5610. * The target can be `window`, `document` or `body`.
  5611. *
  5612. * When writing a directive event binding, you can also refer to the following local variables:
  5613. * - `$event`: Current event object which triggered the event.
  5614. * - `$target`: The source of the event. This will be either a DOM element or an Angular
  5615. * directive. (will be implemented in later release)
  5616. *
  5617. * ## Syntax
  5618. *
  5619. * ```
  5620. * @Directive({
  5621. * host: {
  5622. * '(event1)': 'onMethod1(arguments)',
  5623. * '(target:event2)': 'onMethod2(arguments)',
  5624. * ...
  5625. * }
  5626. * }
  5627. * ```
  5628. *
  5629. * ## Basic Event Binding:
  5630. *
  5631. * Suppose you want to write a directive that reacts to `change` events in the DOM and on
  5632. * `resize` events in window.
  5633. * You would define the event binding as follows:
  5634. *
  5635. * ```
  5636. * @Directive({
  5637. * selector: 'input',
  5638. * host: {
  5639. * '(change)': 'onChange($event)',
  5640. * '(window:resize)': 'onResize($event)'
  5641. * }
  5642. * })
  5643. * class InputDirective {
  5644. * onChange(event:Event) {
  5645. * // invoked when the input element fires the 'change' event
  5646. * }
  5647. * onResize(event:Event) {
  5648. * // invoked when the window fires the 'resize' event
  5649. * }
  5650. * }
  5651. * ```
  5652. *
  5653. * ## Properties
  5654. *
  5655. * Specifies which DOM properties a directives updates.
  5656. *
  5657. * ## Syntax
  5658. *
  5659. * ```
  5660. * @Directive({
  5661. * selector: 'input',
  5662. * host: {
  5663. * '[prop]': 'expression'
  5664. * }
  5665. * })
  5666. * class InputDirective {
  5667. * value:string;
  5668. * }
  5669. * ```
  5670. *
  5671. * In this example the prop property of the host element is updated with the expression value
  5672. * every time it changes.
  5673. *
  5674. * ## Attributes
  5675. *
  5676. * Specifies static attributes that should be propagated to a host element. Attributes specified
  5677. * in `hostAttributes` are propagated only if a given attribute is not present on a host element.
  5678. *
  5679. * ## Syntax
  5680. *
  5681. * ```
  5682. * @Directive({
  5683. * selector: '[my-button]',
  5684. * host: {
  5685. * 'role': 'button'
  5686. * }
  5687. * })
  5688. * class MyButton {
  5689. * }
  5690. * ```
  5691. *
  5692. * In this example using `my-button` directive (ex.: `<div my-button></div>`) on a host element
  5693. * (here: `<div>` ) will ensure that this element will get the "button" role.
  5694. */
  5695. host: StringMap<string, string>;
  5696. /**
  5697. * Specifies which lifecycle should be notified to the directive.
  5698. *
  5699. * See {@link LifecycleEvent} for details.
  5700. */
  5701. lifecycle: LifecycleEvent[];
  5702. /**
  5703. * If set to false the compiler does not compile the children of this directive.
  5704. */
  5705. compileChildren: boolean;
  5706. /**
  5707. * Defines the set of injectable objects that are visible to a Directive and its light dom
  5708. * children.
  5709. *
  5710. * ## Simple Example
  5711. *
  5712. * Here is an example of a class that can be injected:
  5713. *
  5714. * ```
  5715. * class Greeter {
  5716. * greet(name:string) {
  5717. * return 'Hello ' + name + '!';
  5718. * }
  5719. * }
  5720. *
  5721. * @Directive({
  5722. * selector: 'greet',
  5723. * bindings: [
  5724. * Greeter
  5725. * ]
  5726. * })
  5727. * class HelloWorld {
  5728. * greeter:Greeter;
  5729. *
  5730. * constructor(greeter:Greeter) {
  5731. * this.greeter = greeter;
  5732. * }
  5733. * }
  5734. * ```
  5735. */
  5736. bindings: any[];
  5737. /**
  5738. * Defines the name that can be used in the template to assign this directive to a variable.
  5739. *
  5740. * ## Simple Example
  5741. *
  5742. * ```
  5743. * @Directive({
  5744. * selector: 'child-dir',
  5745. * exportAs: 'child'
  5746. * })
  5747. * class ChildDir {
  5748. * }
  5749. *
  5750. * @Component({
  5751. * selector: 'main',
  5752. * })
  5753. * @View({
  5754. * template: `<child-dir #c="child"></child-dir>`,
  5755. * directives: [ChildDir]
  5756. * })
  5757. * class MainComponent {
  5758. * }
  5759. *
  5760. * ```
  5761. */
  5762. exportAs: string;
  5763. }
  5764. /**
  5765. * Declare reusable pipe function.
  5766. *
  5767. * ## Example
  5768. *
  5769. * ```
  5770. * @Pipe({
  5771. * name: 'lowercase'
  5772. * })
  5773. * class Lowercase {
  5774. * transform(v, args) { return v.toLowerCase(); }
  5775. * }
  5776. * ```
  5777. */
  5778. class PipeMetadata extends InjectableMetadata {
  5779. name: string;
  5780. }
  5781. /**
  5782. * Lifecycle events are guaranteed to be called in the following order:
  5783. * - `OnChanges` (if any bindings have changed),
  5784. * - `OnInit` (after the first check only),
  5785. * - `DoCheck`,
  5786. * - `AfterContentChecked`
  5787. * - `AfterContentChecked`
  5788. * - `OnDestroy` (at the very end before destruction)
  5789. */
  5790. enum LifecycleEvent {
  5791. /**
  5792. * Notify a directive when it has been checked the first time.
  5793. *
  5794. * This method is called right after the directive's bindings have been checked,
  5795. * and before any of its children's bindings have been checked.
  5796. *
  5797. * It is invoked only once.
  5798. *
  5799. * ## Example
  5800. *
  5801. * ```
  5802. * @Directive({
  5803. * selector: '[class-set]',
  5804. * lifecycle: [LifecycleEvent.OnInit]
  5805. * })
  5806. * class ClassSet {
  5807. * onInit() {
  5808. * }
  5809. * }
  5810. * ```
  5811. */
  5812. OnInit,
  5813. /**
  5814. * Notify a directive whenever a {@link ViewMetadata} that contains it is destroyed.
  5815. *
  5816. * ## Example
  5817. *
  5818. * ```
  5819. * @Directive({
  5820. * ...,
  5821. * lifecycle: [LifecycleEvent.OnDestroy]
  5822. * })
  5823. * class ClassSet {
  5824. * onDestroy() {
  5825. * // invoked to notify directive of the containing view destruction.
  5826. * }
  5827. * }
  5828. * ```
  5829. */
  5830. OnDestroy,
  5831. /**
  5832. * Notify a directive when any of its bindings have changed.
  5833. *
  5834. * This method is called right after the directive's bindings have been checked,
  5835. * and before any of its children's bindings have been checked.
  5836. *
  5837. * It is invoked only if at least one of the directive's bindings has changed.
  5838. *
  5839. * ## Example:
  5840. *
  5841. * ```
  5842. * @Directive({
  5843. * selector: '[class-set]',
  5844. * properties: [
  5845. * 'propA',
  5846. * 'propB'
  5847. * ],
  5848. * lifecycle: [LifecycleEvent.OnChanges]
  5849. * })
  5850. * class ClassSet {
  5851. * propA;
  5852. * propB;
  5853. * onChanges(changes:{[idx: string, PropertyUpdate]}) {
  5854. * // This will get called after any of the properties have been updated.
  5855. * if (changes['propA']) {
  5856. * // if propA was updated
  5857. * }
  5858. * if (changes['propA']) {
  5859. * // if propB was updated
  5860. * }
  5861. * }
  5862. * }
  5863. * ```
  5864. */
  5865. OnChanges,
  5866. /**
  5867. * Notify a directive when it has been checked.
  5868. *
  5869. * This method is called right after the directive's bindings have been checked,
  5870. * and before any of its children's bindings have been checked.
  5871. *
  5872. * It is invoked every time even when none of the directive's bindings has changed.
  5873. *
  5874. * ## Example
  5875. *
  5876. * ```
  5877. * @Directive({
  5878. * selector: '[class-set]',
  5879. * lifecycle: [LifecycleEvent.DoCheck]
  5880. * })
  5881. * class ClassSet {
  5882. * doCheck() {
  5883. * }
  5884. * }
  5885. * ```
  5886. */
  5887. DoCheck,
  5888. /**
  5889. * Notify a directive when the bindings of all its content children have been checked the first
  5890. * time (whether they
  5891. * have changed or not).
  5892. *
  5893. * ## Example
  5894. *
  5895. * ```
  5896. * @Directive({
  5897. * selector: '[class-set]',
  5898. * lifecycle: [LifecycleEvent.AfterContentInit]
  5899. * })
  5900. * class ClassSet {
  5901. *
  5902. * afterContentInit() {
  5903. * }
  5904. *
  5905. * }
  5906. * ```
  5907. */
  5908. AfterContentInit,
  5909. /**
  5910. * Notify a directive when the bindings of all its content children have been checked (whether
  5911. * they
  5912. * have changed or not).
  5913. *
  5914. * ## Example
  5915. *
  5916. * ```
  5917. * @Directive({
  5918. * selector: '[class-set]',
  5919. * lifecycle: [LifecycleEvent.AfterContentChecked]
  5920. * })
  5921. * class ClassSet {
  5922. *
  5923. * afterContentChecked() {
  5924. * }
  5925. *
  5926. * }
  5927. * ```
  5928. */
  5929. AfterContentChecked,
  5930. /**
  5931. * Notify a directive when the bindings of all its view children have been checked the first time
  5932. * (whether they
  5933. * have changed or not).
  5934. *
  5935. * ## Example
  5936. *
  5937. * ```
  5938. * @Directive({
  5939. * selector: '[class-set]',
  5940. * lifecycle: [LifecycleEvent.AfterViewInit]
  5941. * })
  5942. * class ClassSet {
  5943. *
  5944. * afterViewInit() {
  5945. * }
  5946. *
  5947. * }
  5948. * ```
  5949. */
  5950. AfterViewInit,
  5951. /**
  5952. * Notify a directive when the bindings of all its view children have been checked (whether they
  5953. * have changed or not).
  5954. *
  5955. * ## Example
  5956. *
  5957. * ```
  5958. * @Directive({
  5959. * selector: '[class-set]',
  5960. * lifecycle: [LifecycleEvent.AfterViewChecked]
  5961. * })
  5962. * class ClassSet {
  5963. *
  5964. * afterViewChecked() {
  5965. * }
  5966. *
  5967. * }
  5968. * ```
  5969. */
  5970. AfterViewChecked
  5971. }
  5972. /**
  5973. * Declares the available HTML templates for an application.
  5974. *
  5975. * Each angular component requires a single `@Component` and at least one `@View` annotation. The
  5976. * `@View` annotation specifies the HTML template to use, and lists the directives that are active
  5977. * within the template.
  5978. *
  5979. * When a component is instantiated, the template is loaded into the component's shadow root, and
  5980. * the expressions and statements in the template are evaluated against the component.
  5981. *
  5982. * For details on the `@Component` annotation, see {@link ComponentMetadata}.
  5983. *
  5984. * ## Example
  5985. *
  5986. * ```
  5987. * @Component({
  5988. * selector: 'greet'
  5989. * })
  5990. * @View({
  5991. * template: 'Hello {{name}}!',
  5992. * directives: [GreetUser, Bold]
  5993. * })
  5994. * class Greet {
  5995. * name: string;
  5996. *
  5997. * constructor() {
  5998. * this.name = 'World';
  5999. * }
  6000. * }
  6001. * ```
  6002. */
  6003. class ViewMetadata {
  6004. /**
  6005. * Specifies a template URL for an angular component.
  6006. *
  6007. * NOTE: either `templateUrl` or `template` should be used, but not both.
  6008. */
  6009. templateUrl: string;
  6010. /**
  6011. * Specifies an inline template for an angular component.
  6012. *
  6013. * NOTE: either `templateUrl` or `template` should be used, but not both.
  6014. */
  6015. template: string;
  6016. /**
  6017. * Specifies stylesheet URLs for an angular component.
  6018. */
  6019. styleUrls: string[];
  6020. /**
  6021. * Specifies an inline stylesheet for an angular component.
  6022. */
  6023. styles: string[];
  6024. /**
  6025. * Specifies a list of directives that can be used within a template.
  6026. *
  6027. * Directives must be listed explicitly to provide proper component encapsulation.
  6028. *
  6029. * ## Example
  6030. *
  6031. * ```javascript
  6032. * @Component({
  6033. * selector: 'my-component'
  6034. * })
  6035. * @View({
  6036. * directives: [For]
  6037. * template: '
  6038. * <ul>
  6039. * <li *ng-for="#item of items">{{item}}</li>
  6040. * </ul>'
  6041. * })
  6042. * class MyComponent {
  6043. * }
  6044. * ```
  6045. */
  6046. directives: Array<Type | any | any[]>;
  6047. pipes: Array<Type | any | any[]>;
  6048. /**
  6049. * Specify how the template and the styles should be encapsulated.
  6050. * The default is {@link ViewEncapsulation#Emulated `ViewEncapsulation.Emulated`} if the view
  6051. * has styles,
  6052. * otherwise {@link ViewEncapsulation#None `ViewEncapsulation.None`}.
  6053. */
  6054. encapsulation: ViewEncapsulation;
  6055. }
  6056. /**
  6057. * How the template and styles of a view should be encapsulated.
  6058. */
  6059. enum ViewEncapsulation {
  6060. /**
  6061. * Emulate scoping of styles by preprocessing the style rules
  6062. * and adding additional attributes to elements. This is the default.
  6063. */
  6064. Emulated,
  6065. /**
  6066. * Uses the native mechanism of the renderer. For the DOM this means creating a ShadowRoot.
  6067. */
  6068. Native,
  6069. /**
  6070. * Don't scope the template nor the styles.
  6071. */
  6072. None
  6073. }
  6074. /**
  6075. * Specifies that a {@link QueryList} should be injected.
  6076. *
  6077. * See {@link QueryList} for usage and example.
  6078. */
  6079. class QueryMetadata extends DependencyMetadata {
  6080. descendants: boolean;
  6081. isViewQuery: any;
  6082. selector: any;
  6083. isVarBindingQuery: boolean;
  6084. varBindings: string[];
  6085. toString(): string;
  6086. }
  6087. /**
  6088. * Specifies that a constant attribute value should be injected.
  6089. *
  6090. * The directive can inject constant string literals of host element attributes.
  6091. *
  6092. * ## Example
  6093. *
  6094. * Suppose we have an `<input>` element and want to know its `type`.
  6095. *
  6096. * ```html
  6097. * <input type="text">
  6098. * ```
  6099. *
  6100. * A decorator can inject string literal `text` like so:
  6101. *
  6102. * ```javascript
  6103. * @Directive({
  6104. * selector: `input'
  6105. * })
  6106. * class InputDirective {
  6107. * constructor(@Attribute('type') type) {
  6108. * // type would be `text` in this example
  6109. * }
  6110. * }
  6111. * ```
  6112. */
  6113. class AttributeMetadata extends DependencyMetadata {
  6114. attributeName: string;
  6115. token: any;
  6116. toString(): string;
  6117. }
  6118. /**
  6119. * {@link AttributeMetadata} factory function.
  6120. */
  6121. var Attribute : AttributeFactory ;
  6122. /**
  6123. * {@link AttributeMetadata} factory for creating annotations, decorators or DSL.
  6124. *
  6125. * ## Example as TypeScript Decorator
  6126. *
  6127. * ```
  6128. * import {Attribute, Component, View} from "angular2/angular2";
  6129. *
  6130. * @Component({...})
  6131. * @View({...})
  6132. * class MyComponent {
  6133. * constructor(@Attribute('title') title: string) {
  6134. * ...
  6135. * }
  6136. * }
  6137. * ```
  6138. *
  6139. * ## Example as ES5 DSL
  6140. *
  6141. * ```
  6142. * var MyComponent = ng
  6143. * .Component({...})
  6144. * .View({...})
  6145. * .Class({
  6146. * constructor: [new ng.Attribute('title'), function(title) {
  6147. * ...
  6148. * }]
  6149. * })
  6150. * ```
  6151. *
  6152. * ## Example as ES5 annotation
  6153. *
  6154. * ```
  6155. * var MyComponent = function(title) {
  6156. * ...
  6157. * };
  6158. *
  6159. * MyComponent.annotations = [
  6160. * new ng.Component({...}),
  6161. * new ng.View({...})
  6162. * ]
  6163. * MyComponent.parameters = [
  6164. * [new ng.Attribute('title')]
  6165. * ]
  6166. * ```
  6167. */
  6168. interface AttributeFactory {
  6169. new(name: string): AttributeMetadata;
  6170. (name: string): TypeDecorator;
  6171. }
  6172. /**
  6173. * {@link ComponentMetadata} factory function.
  6174. */
  6175. var Component : ComponentFactory ;
  6176. /**
  6177. * Interface for the {@link ComponentMetadata} decorator function.
  6178. *
  6179. * See {@link ComponentFactory}.
  6180. */
  6181. interface ComponentDecorator extends TypeDecorator {
  6182. /**
  6183. * Chain {@link ViewMetadata} annotation.
  6184. */
  6185. View(obj: {
  6186. templateUrl?: string,
  6187. template?: string,
  6188. directives?: Array<Type | any | any[]>,
  6189. pipes?: Array<Type | any | any[]>,
  6190. renderer?: string,
  6191. styles?: string[],
  6192. styleUrls?: string[],
  6193. }): ViewDecorator;
  6194. }
  6195. /**
  6196. * {@link ComponentAnnotation} factory for creating annotations, decorators or DSL.
  6197. *
  6198. * ## Example as TypeScript Decorator
  6199. *
  6200. * ```
  6201. * import {Component, View} from "angular2/angular2";
  6202. *
  6203. * @Component({...})
  6204. * @View({...})
  6205. * class MyComponent {
  6206. * constructor() {
  6207. * ...
  6208. * }
  6209. * }
  6210. * ```
  6211. *
  6212. * ## Example as ES5 DSL
  6213. *
  6214. * ```
  6215. * var MyComponent = ng
  6216. * .Component({...})
  6217. * .View({...})
  6218. * .Class({
  6219. * constructor: function() {
  6220. * ...
  6221. * }
  6222. * })
  6223. * ```
  6224. *
  6225. * ## Example as ES5 annotation
  6226. *
  6227. * ```
  6228. * var MyComponent = function() {
  6229. * ...
  6230. * };
  6231. *
  6232. * MyComponent.annotations = [
  6233. * new ng.Component({...}),
  6234. * new ng.View({...})
  6235. * ]
  6236. * ```
  6237. */
  6238. interface ComponentFactory {
  6239. new(obj: {
  6240. selector?: string,
  6241. properties?: string[],
  6242. events?: string[],
  6243. host?: StringMap<string, string>,
  6244. lifecycle?: LifecycleEvent[],
  6245. bindings?: any[],
  6246. exportAs?: string,
  6247. compileChildren?: boolean,
  6248. viewBindings?: any[],
  6249. changeDetection?: ChangeDetectionStrategy,
  6250. }): ComponentMetadata;
  6251. (obj: {
  6252. selector?: string,
  6253. properties?: string[],
  6254. events?: string[],
  6255. host?: StringMap<string, string>,
  6256. lifecycle?: LifecycleEvent[],
  6257. bindings?: any[],
  6258. exportAs?: string,
  6259. compileChildren?: boolean,
  6260. viewBindings?: any[],
  6261. changeDetection?: ChangeDetectionStrategy,
  6262. }): ComponentDecorator;
  6263. }
  6264. /**
  6265. * {@link DirectiveMetadata} factory function.
  6266. */
  6267. var Directive : DirectiveFactory ;
  6268. /**
  6269. * Interface for the {@link DirectiveMetadata} decorator function.
  6270. *
  6271. * See {@link DirectiveFactory}.
  6272. */
  6273. interface DirectiveDecorator extends TypeDecorator {
  6274. }
  6275. /**
  6276. * {@link DirectiveMetadata} factory for creating annotations, decorators or DSL.
  6277. *
  6278. * ## Example as TypeScript Decorator
  6279. *
  6280. * ```
  6281. * import {Directive} from "angular2/angular2";
  6282. *
  6283. * @Directive({...})
  6284. * class MyDirective {
  6285. * constructor() {
  6286. * ...
  6287. * }
  6288. * }
  6289. * ```
  6290. *
  6291. * ## Example as ES5 DSL
  6292. *
  6293. * ```
  6294. * var MyDirective = ng
  6295. * .Directive({...})
  6296. * .Class({
  6297. * constructor: function() {
  6298. * ...
  6299. * }
  6300. * })
  6301. * ```
  6302. *
  6303. * ## Example as ES5 annotation
  6304. *
  6305. * ```
  6306. * var MyDirective = function() {
  6307. * ...
  6308. * };
  6309. *
  6310. * MyDirective.annotations = [
  6311. * new ng.Directive({...})
  6312. * ]
  6313. * ```
  6314. */
  6315. interface DirectiveFactory {
  6316. new(obj: {
  6317. selector?: string, properties?: string[], events?: string[], host?: StringMap<string, string>,
  6318. lifecycle?: LifecycleEvent[], bindings?: any[], exportAs?: string,
  6319. compileChildren?: boolean;
  6320. }): DirectiveMetadata;
  6321. (obj: {
  6322. selector?: string, properties?: string[], events?: string[], host?: StringMap<string, string>,
  6323. lifecycle?: LifecycleEvent[], bindings?: any[], exportAs?: string,
  6324. compileChildren?: boolean;
  6325. }): DirectiveDecorator;
  6326. }
  6327. /**
  6328. * {@link ViewMetadata} factory function.
  6329. */
  6330. var View : ViewFactory ;
  6331. /**
  6332. * Interface for the {@link ViewMetadata} decorator function.
  6333. *
  6334. * See {@link ViewFactory}.
  6335. */
  6336. interface ViewDecorator extends TypeDecorator {
  6337. /**
  6338. * Chain {@link ViewMetadata} annotation.
  6339. */
  6340. View(obj: {
  6341. templateUrl?: string,
  6342. template?: string,
  6343. directives?: Array<Type | any | any[]>,
  6344. pipes?: Array<Type | any | any[]>,
  6345. renderer?: string,
  6346. styles?: string[],
  6347. styleUrls?: string[],
  6348. }): ViewDecorator;
  6349. }
  6350. /**
  6351. * {@link ViewAnnotation} factory for creating annotations, decorators or DSL.
  6352. *
  6353. * ## Example as TypeScript Decorator
  6354. *
  6355. * ```
  6356. * import {Component, View} from "angular2/angular2";
  6357. *
  6358. * @Component({...})
  6359. * @View({...})
  6360. * class MyComponent {
  6361. * constructor() {
  6362. * ...
  6363. * }
  6364. * }
  6365. * ```
  6366. *
  6367. * ## Example as ES5 DSL
  6368. *
  6369. * ```
  6370. * var MyComponent = ng
  6371. * .Component({...})
  6372. * .View({...})
  6373. * .Class({
  6374. * constructor: function() {
  6375. * ...
  6376. * }
  6377. * })
  6378. * ```
  6379. *
  6380. * ## Example as ES5 annotation
  6381. *
  6382. * ```
  6383. * var MyComponent = function() {
  6384. * ...
  6385. * };
  6386. *
  6387. * MyComponent.annotations = [
  6388. * new ng.Component({...}),
  6389. * new ng.View({...})
  6390. * ]
  6391. * ```
  6392. */
  6393. interface ViewFactory {
  6394. new(obj: {
  6395. templateUrl?: string,
  6396. template?: string,
  6397. directives?: Array<Type | any | any[]>,
  6398. encapsulation?: ViewEncapsulation,
  6399. styles?: string[],
  6400. styleUrls?: string[],
  6401. }): ViewMetadata;
  6402. (obj: {
  6403. templateUrl?: string,
  6404. template?: string,
  6405. directives?: Array<Type | any | any[]>,
  6406. encapsulation?: ViewEncapsulation,
  6407. styles?: string[],
  6408. styleUrls?: string[],
  6409. }): ViewDecorator;
  6410. }
  6411. /**
  6412. * {@link QueryMetadata} factory function.
  6413. */
  6414. var Query : QueryFactory ;
  6415. /**
  6416. * {@link QueryMetadata} factory for creating annotations, decorators or DSL.
  6417. *
  6418. * ## Example as TypeScript Decorator
  6419. *
  6420. * ```
  6421. * import {Query, QueryList, Component, View} from "angular2/angular2";
  6422. *
  6423. * @Component({...})
  6424. * @View({...})
  6425. * class MyComponent {
  6426. * constructor(@Query(SomeType) queryList: QueryList) {
  6427. * ...
  6428. * }
  6429. * }
  6430. * ```
  6431. *
  6432. * ## Example as ES5 DSL
  6433. *
  6434. * ```
  6435. * var MyComponent = ng
  6436. * .Component({...})
  6437. * .View({...})
  6438. * .Class({
  6439. * constructor: [new ng.Query(SomeType), function(queryList) {
  6440. * ...
  6441. * }]
  6442. * })
  6443. * ```
  6444. *
  6445. * ## Example as ES5 annotation
  6446. *
  6447. * ```
  6448. * var MyComponent = function(queryList) {
  6449. * ...
  6450. * };
  6451. *
  6452. * MyComponent.annotations = [
  6453. * new ng.Component({...}),
  6454. * new ng.View({...})
  6455. * ]
  6456. * MyComponent.parameters = [
  6457. * [new ng.Query(SomeType)]
  6458. * ]
  6459. * ```
  6460. */
  6461. interface QueryFactory {
  6462. new(selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata;
  6463. (selector: Type | string, {descendants}?: {descendants?: boolean}): ParameterDecorator;
  6464. }
  6465. /**
  6466. * {@link di/ViewQueryMetadata} factory function.
  6467. */
  6468. var ViewQuery : QueryFactory ;
  6469. /**
  6470. * {@link PipeMetadata} factory function.
  6471. */
  6472. var Pipe : PipeFactory ;
  6473. /**
  6474. * {@link PipeMetadata} factory for creating decorators.
  6475. *
  6476. * ## Example as TypeScript Decorator
  6477. *
  6478. * ```
  6479. * import {Pipe} from "angular2/angular2";
  6480. *
  6481. * @Pipe({...})
  6482. * class MyPipe {
  6483. * constructor() {
  6484. * ...
  6485. * }
  6486. *
  6487. * transform(v, args) {}
  6488. * }
  6489. * ```
  6490. */
  6491. interface PipeFactory {
  6492. new(obj: {
  6493. name: string,
  6494. }): any;
  6495. (obj: {name: string}): any;
  6496. }
  6497. /**
  6498. * Defines lifecycle method
  6499. * {@link metadata/LifeCycleEvent#AfterContentInit `LifeCycleEvent.afterContentInit`}
  6500. * called when the bindings of all its content children have been checked the first time.
  6501. */
  6502. interface AfterContentInit {
  6503. afterContentInit(): void;
  6504. }
  6505. /**
  6506. * Defines lifecycle method
  6507. * {@link metadata/LifeCycleEvent#AfterContentChecked `LifeCycleEvent.afterContentChecked`}
  6508. * called when the bindings of all its content children have been checked.
  6509. */
  6510. interface AfterContentChecked {
  6511. afterContentChecked(): void;
  6512. }
  6513. /**
  6514. * Defines lifecycle method
  6515. * {@link metadata/LifeCycleEvent#AfterViewInit `LifeCycleEvent.afterViewInit`}
  6516. * called when the bindings of all its view children have been checked the first time.
  6517. */
  6518. interface AfterViewInit {
  6519. afterViewInit(): void;
  6520. }
  6521. /**
  6522. * Defines lifecycle method
  6523. * {@link metadata/LifeCycleEvent#AfterViewChecked `LifeCycleEvent.afterViewChecked`}
  6524. * called when the bindings of all its view children have been checked.
  6525. */
  6526. interface AfterViewChecked {
  6527. afterViewChecked(): void;
  6528. }
  6529. /**
  6530. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnChanges `LifeCycleEvent.OnChanges`}
  6531. * called after all of component's bound properties are updated.
  6532. */
  6533. interface OnChanges {
  6534. onChanges(changes: StringMap<string, any>): void;
  6535. }
  6536. /**
  6537. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnDestroy `LifeCycleEvent.OnDestroy`}
  6538. * called when a directive is being destroyed.
  6539. */
  6540. interface OnDestroy {
  6541. onDestroy(): void;
  6542. }
  6543. /**
  6544. * Defines lifecycle method {@link metadata/LifeCycleEvent#OnInit `LifeCycleEvent.OnInit`}
  6545. * called when a directive is being checked the first time.
  6546. */
  6547. interface OnInit {
  6548. onInit(): void;
  6549. }
  6550. /**
  6551. * Defines lifecycle method {@link metadata/LifeCycleEvent#DoCheck `LifeCycleEvent.DoCheck`}
  6552. * called when a directive is being checked.
  6553. */
  6554. interface DoCheck {
  6555. doCheck(): boolean;
  6556. }
  6557. /**
  6558. * Provides a way for expressing ES6 classes with parameter annotations in ES5.
  6559. *
  6560. * ## Basic Example
  6561. *
  6562. * ```
  6563. * var Greeter = ng.Class({
  6564. * constructor: function(name) {
  6565. * this.name = name;
  6566. * },
  6567. *
  6568. * greet: function() {
  6569. * alert('Hello ' + this.name + '!');
  6570. * }
  6571. * });
  6572. * ```
  6573. *
  6574. * is equivalent to ES6:
  6575. *
  6576. * ```
  6577. * class Greeter {
  6578. * constructor(name) {
  6579. * this.name = name;
  6580. * }
  6581. *
  6582. * greet() {
  6583. * alert('Hello ' + this.name + '!');
  6584. * }
  6585. * }
  6586. * ```
  6587. *
  6588. * or equivalent to ES5:
  6589. *
  6590. * ```
  6591. * var Greeter = function (name) {
  6592. * this.name = name;
  6593. * }
  6594. *
  6595. * Greeter.prototype.greet = function () {
  6596. * alert('Hello ' + this.name + '!');
  6597. * }
  6598. * ```
  6599. *
  6600. * ## Example with parameter annotations
  6601. *
  6602. * ```
  6603. * var MyService = neg.Class({
  6604. * constructor: [String, [new Query(), QueryList], function(name, queryList) {
  6605. * ...
  6606. * }];
  6607. * });
  6608. * ```
  6609. *
  6610. * is equivalent to ES6:
  6611. *
  6612. * ```
  6613. * class MyService {
  6614. * constructor(name: string, @Query() queryList: QueryList) {
  6615. * ...
  6616. * }
  6617. * }
  6618. * ```
  6619. *
  6620. * ## Example with inheritance
  6621. *
  6622. * ```
  6623. * var Shape = ng.Class({
  6624. * constructor: (color) {
  6625. * this.color = color;
  6626. * }
  6627. * });
  6628. *
  6629. * var Square = ng.Class({
  6630. * extends: Shape,
  6631. * constructor: function(color, size) {
  6632. * Shape.call(this, color);
  6633. * this.size = size;
  6634. * }
  6635. * });
  6636. * ```
  6637. */
  6638. function Class(clsDef: ClassDefinition) : Type ;
  6639. /**
  6640. * Declares the interface to be used with {@link Class}.
  6641. */
  6642. interface ClassDefinition {
  6643. /**
  6644. * Optional argument for specifying the superclass.
  6645. */
  6646. extends?: Type;
  6647. /**
  6648. * Required constructor function for a class.
  6649. *
  6650. * The function may be optionally wrapped in an `Array`, in which case additional parameter
  6651. * annotations may be specified.
  6652. * The number of arguments and the number of parameter annotations must match.
  6653. *
  6654. * See {@link Class} for example of usage.
  6655. */
  6656. constructor: (Function | any[]);
  6657. }
  6658. /**
  6659. * An interface implemented by all Angular type decorators, which allows them to be used as ES7
  6660. * decorators as well as
  6661. * Angular DSL syntax.
  6662. *
  6663. * DSL syntax:
  6664. *
  6665. * ```
  6666. * var MyClass = ng
  6667. * .Component({...})
  6668. * .View({...})
  6669. * .Class({...});
  6670. * ```
  6671. *
  6672. * ES7 syntax:
  6673. *
  6674. * ```
  6675. * @ng.Component({...})
  6676. * @ng.View({...})
  6677. * class MyClass {...}
  6678. * ```
  6679. */
  6680. interface TypeDecorator {
  6681. /**
  6682. * Invoke as ES7 decorator.
  6683. */
  6684. <T extends Type>(type: T): T;
  6685. /**
  6686. * Storage for the accumulated annotations so far used by the DSL syntax.
  6687. *
  6688. * Used by {@link Class} to annotate the generated class.
  6689. */
  6690. annotations: any[];
  6691. /**
  6692. * Generate a class from the definition and annotate it with {@link TypeDecorator#annotations}.
  6693. */
  6694. Class(obj: ClassDefinition): Type;
  6695. }
  6696. enum ChangeDetectionStrategy {
  6697. /**
  6698. * `CheckedOnce` means that after calling detectChanges the mode of the change detector
  6699. * will become `Checked`.
  6700. */
  6701. CheckOnce,
  6702. /**
  6703. * `Checked` means that the change detector should be skipped until its mode changes to
  6704. * `CheckOnce`.
  6705. */
  6706. Checked,
  6707. /**
  6708. * `CheckAlways` means that after calling detectChanges the mode of the change detector
  6709. * will remain `CheckAlways`.
  6710. */
  6711. CheckAlways,
  6712. /**
  6713. * `Detached` means that the change detector sub tree is not a part of the main tree and
  6714. * should be skipped.
  6715. */
  6716. Detached,
  6717. /**
  6718. * `OnPush` means that the change detector's mode will be set to `CheckOnce` during hydration.
  6719. */
  6720. OnPush,
  6721. /**
  6722. * `Default` means that the change detector's mode will be set to `CheckAlways` during hydration.
  6723. */
  6724. Default,
  6725. /**
  6726. * This is an experimental feature. Works only in Dart.
  6727. */
  6728. OnPushObserve
  6729. }
  6730. /**
  6731. * An error thrown if application changes model breaking the top-down data flow.
  6732. *
  6733. * Angular expects that the data flows from top (root) component to child (leaf) components.
  6734. * This is known as directed acyclic graph. This allows Angular to only execute change detection
  6735. * once and prevents loops in change detection data flow.
  6736. *
  6737. * This exception is only thrown in dev mode.
  6738. */
  6739. class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
  6740. }
  6741. /**
  6742. * Thrown when an expression evaluation raises an exception.
  6743. *
  6744. * This error wraps the original exception, this is done to attach expression location information.
  6745. */
  6746. class ChangeDetectionError extends BaseException {
  6747. /**
  6748. * Location of the expression.
  6749. */
  6750. location: string;
  6751. }
  6752. interface ChangeDetector {
  6753. parent: ChangeDetector;
  6754. mode: ChangeDetectionStrategy;
  6755. ref: ChangeDetectorRef;
  6756. addChild(cd: ChangeDetector): void;
  6757. addShadowDomChild(cd: ChangeDetector): void;
  6758. removeChild(cd: ChangeDetector): void;
  6759. removeShadowDomChild(cd: ChangeDetector): void;
  6760. remove(): void;
  6761. hydrate(context: any, locals: Locals, directives: any, pipes: any): void;
  6762. dehydrate(): void;
  6763. markPathToRootAsCheckOnce(): void;
  6764. handleEvent(eventName: string, elIndex: number, locals: Locals): void;
  6765. detectChanges(): void;
  6766. checkNoChanges(): void;
  6767. }
  6768. class Locals {
  6769. parent: Locals;
  6770. current: Map<any, any>;
  6771. contains(name: string): boolean;
  6772. get(name: string): any;
  6773. set(name: string, value: any): void;
  6774. clearValues(): void;
  6775. }
  6776. /**
  6777. * Controls change detection.
  6778. *
  6779. * {@link ChangeDetectorRef} allows requesting checks for detectors that rely on observables. It
  6780. * also allows detaching and attaching change detector subtrees.
  6781. */
  6782. interface ChangeDetectorRef {
  6783. /**
  6784. * Request to check all OnPush ancestors.
  6785. */
  6786. markForCheck(): void;
  6787. /**
  6788. * Detaches the change detector from the change detector tree.
  6789. *
  6790. * The detached change detector will not be checked until it is reattached.
  6791. */
  6792. detach(): void;
  6793. /**
  6794. * Reattach the change detector to the change detector tree.
  6795. *
  6796. * This also requests a check of this change detector. This reattached change detector will be
  6797. * checked during the next change detection run.
  6798. */
  6799. reattach(): void;
  6800. }
  6801. /**
  6802. * Indicates that the result of a {@link PipeMetadata} transformation has changed even though the
  6803. * reference
  6804. * has not changed.
  6805. *
  6806. * The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
  6807. *
  6808. * Example:
  6809. *
  6810. * ```
  6811. * if (this._latestValue === this._latestReturnedValue) {
  6812. * return this._latestReturnedValue;
  6813. * } else {
  6814. * this._latestReturnedValue = this._latestValue;
  6815. * return WrappedValue.wrap(this._latestValue); // this will force update
  6816. * }
  6817. * ```
  6818. */
  6819. class WrappedValue {
  6820. static wrap(value: any): WrappedValue;
  6821. wrapped: any;
  6822. }
  6823. /**
  6824. * An interface which all pipes must implement.
  6825. *
  6826. * #Example
  6827. *
  6828. * ```
  6829. * class DoublePipe implements PipeTransform {
  6830. * transform(value, args = []) {
  6831. * return `${value}${value}`;
  6832. * }
  6833. * }
  6834. * ```
  6835. */
  6836. interface PipeTransform {
  6837. transform(value: any, args: any[]): any;
  6838. }
  6839. /**
  6840. * An interface that stateful pipes should implement.
  6841. *
  6842. * #Example
  6843. *
  6844. * ```
  6845. * class StatefulPipe implements PipeTransform, PipeOnDestroy {
  6846. * connection;
  6847. *
  6848. * onDestroy() {
  6849. * this.connection.release();
  6850. * }
  6851. *
  6852. * transform(value, args = []) {
  6853. * this.connection = createConnection();
  6854. * // ...
  6855. * return someValue;
  6856. * }
  6857. * }
  6858. * ```
  6859. */
  6860. interface PipeOnDestroy {
  6861. onDestroy(): void;
  6862. }
  6863. /**
  6864. * A repository of different iterable diffing strategies used by NgFor, NgClass, and others.
  6865. */
  6866. class IterableDiffers {
  6867. static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers;
  6868. /**
  6869. * Takes an array of {@link IterableDifferFactory} and returns a binding used to extend the
  6870. * inherited {@link IterableDiffers} instance with the provided factories and return a new
  6871. * {@link IterableDiffers} instance.
  6872. *
  6873. * The following example shows how to extend an existing list of factories,
  6874. * which will only be applied to the injector for this component and its children.
  6875. * This step is all that's required to make a new {@link IterableDiffer} available.
  6876. *
  6877. * # Example
  6878. *
  6879. * ```
  6880. * @Component({
  6881. * viewBindings: [
  6882. * IterableDiffers.extend([new ImmutableListDiffer()])
  6883. * ]
  6884. * })
  6885. * ```
  6886. */
  6887. static extend(factories: IterableDifferFactory[]): Binding;
  6888. factories: IterableDifferFactory[];
  6889. find(iterable: Object): IterableDifferFactory;
  6890. }
  6891. interface IterableDiffer {
  6892. diff(object: Object): any;
  6893. onDestroy(): void;
  6894. }
  6895. /**
  6896. * Provides a factory for {@link IterableDiffer}.
  6897. */
  6898. interface IterableDifferFactory {
  6899. supports(objects: Object): boolean;
  6900. create(cdRef: ChangeDetectorRef): IterableDiffer;
  6901. }
  6902. /**
  6903. * A repository of different Map diffing strategies used by NgClass, NgStyle, and others.
  6904. */
  6905. class KeyValueDiffers {
  6906. static create(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers;
  6907. /**
  6908. * Takes an array of {@link KeyValueDifferFactory} and returns a binding used to extend the
  6909. * inherited {@link KeyValueDiffers} instance with the provided factories and return a new
  6910. * {@link KeyValueDiffers} instance.
  6911. *
  6912. * The following example shows how to extend an existing list of factories,
  6913. * which will only be applied to the injector for this component and its children.
  6914. * This step is all that's required to make a new {@link KeyValueDiffer} available.
  6915. *
  6916. * # Example
  6917. *
  6918. * ```
  6919. * @Component({
  6920. * viewBindings: [
  6921. * KeyValueDiffers.extend([new ImmutableMapDiffer()])
  6922. * ]
  6923. * })
  6924. * ```
  6925. */
  6926. static extend(factories: KeyValueDifferFactory[]): Binding;
  6927. factories: KeyValueDifferFactory[];
  6928. find(kv: Object): KeyValueDifferFactory;
  6929. }
  6930. interface KeyValueDiffer {
  6931. diff(object: Object): void;
  6932. onDestroy(): void;
  6933. }
  6934. /**
  6935. * Provides a factory for {@link KeyValueDiffer}.
  6936. */
  6937. interface KeyValueDifferFactory {
  6938. supports(objects: Object): boolean;
  6939. create(cdRef: ChangeDetectorRef): KeyValueDiffer;
  6940. }
  6941. /**
  6942. * An opaque token representing the application root type in the {@link Injector}.
  6943. *
  6944. * ```
  6945. * @Component(...)
  6946. * @View(...)
  6947. * class MyApp {
  6948. * ...
  6949. * }
  6950. *
  6951. * bootstrap(MyApp).then((appRef:ApplicationRef) {
  6952. * expect(appRef.injector.get(appComponentTypeToken)).toEqual(MyApp);
  6953. * });
  6954. *
  6955. * ```
  6956. */
  6957. const APP_COMPONENT : OpaqueToken ;
  6958. /**
  6959. * Runtime representation of a type.
  6960. *
  6961. * In JavaScript a Type is a constructor function.
  6962. */
  6963. interface Type extends Function {
  6964. new(...args: any[]): any;
  6965. }
  6966. /**
  6967. * Represents a Angular's representation of an Application.
  6968. *
  6969. * `ApplicationRef` represents a running application instance. Use it to retrieve the host
  6970. * component, injector,
  6971. * or dispose of an application.
  6972. */
  6973. interface ApplicationRef {
  6974. /**
  6975. * Returns the current {@link ComponentMetadata} type.
  6976. */
  6977. hostComponentType: Type;
  6978. /**
  6979. * Returns the current {@link ComponentMetadata} instance.
  6980. */
  6981. hostComponent: any;
  6982. /**
  6983. * Dispose (un-load) the application.
  6984. */
  6985. dispose(): void;
  6986. /**
  6987. * Returns the root application {@link Injector}.
  6988. */
  6989. injector: Injector;
  6990. }
  6991. /**
  6992. * Specifies app root url for the application.
  6993. *
  6994. * Used by the {@link Compiler} when resolving HTML and CSS template URLs.
  6995. *
  6996. * This interface can be overridden by the application developer to create custom behavior.
  6997. *
  6998. * See {@link Compiler}
  6999. */
  7000. class AppRootUrl {
  7001. /**
  7002. * Returns the base URL of the currently running application.
  7003. */
  7004. value: any;
  7005. }
  7006. /**
  7007. * Used by the {@link Compiler} when resolving HTML and CSS template URLs.
  7008. *
  7009. * This interface can be overridden by the application developer to create custom behavior.
  7010. *
  7011. * See {@link Compiler}
  7012. */
  7013. class UrlResolver {
  7014. /**
  7015. * Resolves the `url` given the `baseUrl`:
  7016. * - when the `url` is null, the `baseUrl` is returned,
  7017. * - if `url` is relative ('path/to/here', './path/to/here'), the resolved url is a combination of
  7018. * `baseUrl` and `url`,
  7019. * - if `url` is absolute (it has a scheme: 'http://', 'https://' or start with '/'), the `url` is
  7020. * returned as is (ignoring the `baseUrl`)
  7021. *
  7022. * @param {string} baseUrl
  7023. * @param {string} url
  7024. * @returns {string} the resolved URL
  7025. */
  7026. resolve(baseUrl: string, url: string): string;
  7027. }
  7028. /**
  7029. * Resolve a `Type` from a {@link ComponentMetadata} into a URL.
  7030. *
  7031. * This interface can be overridden by the application developer to create custom behavior.
  7032. *
  7033. * See {@link Compiler}
  7034. */
  7035. class ComponentUrlMapper {
  7036. /**
  7037. * Returns the base URL to the component source file.
  7038. * The returned URL could be:
  7039. * - an absolute URL,
  7040. * - a path relative to the application
  7041. */
  7042. getUrl(component: Type): string;
  7043. }
  7044. /**
  7045. * Resolve a `Type` for {@link DirectiveMetadata}.
  7046. *
  7047. * This interface can be overridden by the application developer to create custom behavior.
  7048. *
  7049. * See {@link Compiler}
  7050. */
  7051. class DirectiveResolver {
  7052. /**
  7053. * Return {@link DirectiveMetadata} for a given `Type`.
  7054. */
  7055. resolve(type: Type): DirectiveMetadata;
  7056. }
  7057. /**
  7058. * ## URL Resolution
  7059. *
  7060. * ```
  7061. * var appRootUrl: AppRootUrl = ...;
  7062. * var componentUrlMapper: ComponentUrlMapper = ...;
  7063. * var urlResolver: UrlResolver = ...;
  7064. *
  7065. * var componentType: Type = ...;
  7066. * var componentAnnotation: ComponentAnnotation = ...;
  7067. * var viewAnnotation: ViewAnnotation = ...;
  7068. *
  7069. * // Resolving a URL
  7070. *
  7071. * var url = viewAnnotation.templateUrl;
  7072. * var componentUrl = componentUrlMapper.getUrl(componentType);
  7073. * var componentResolvedUrl = urlResolver.resolve(appRootUrl.value, componentUrl);
  7074. * var templateResolvedUrl = urlResolver.resolve(componetResolvedUrl, url);
  7075. * ```
  7076. */
  7077. interface Compiler {
  7078. compileInHost(componentTypeOrBinding: Type | Binding): Promise<ProtoViewRef>;
  7079. }
  7080. /**
  7081. * Entry point for creating, moving views in the view hierarchy and destroying views.
  7082. * This manager contains all recursion and delegates to helper methods
  7083. * in AppViewManagerUtils and the Renderer, so unit tests get simpler.
  7084. */
  7085. interface AppViewManager {
  7086. /**
  7087. * Returns a {@link ViewContainerRef} at the {@link ElementRef} location.
  7088. */
  7089. getViewContainer(location: ElementRef): ViewContainerRef;
  7090. /**
  7091. * Return the first child element of the host element view.
  7092. */
  7093. getHostElement(hostViewRef: HostViewRef): ElementRef;
  7094. /**
  7095. * Returns an ElementRef for the element with the given variable name
  7096. * in the current view.
  7097. *
  7098. * - `hostLocation`: {@link ElementRef} of any element in the View which defines the scope of
  7099. * search.
  7100. * - `variableName`: Name of the variable to locate.
  7101. * - Returns {@link ElementRef} of the found element or null. (Throws if not found.)
  7102. */
  7103. getNamedElementInComponentView(hostLocation: ElementRef, variableName: string): ElementRef;
  7104. /**
  7105. * Returns the component instance for a given element.
  7106. *
  7107. * The component is the execution context as seen by an expression at that {@link ElementRef}
  7108. * location.
  7109. */
  7110. getComponent(hostLocation: ElementRef): any;
  7111. /**
  7112. * Load component view into existing element.
  7113. *
  7114. * Use this if a host element is already in the DOM and it is necessary to upgrade
  7115. * the element into Angular component by attaching a view but reusing the existing element.
  7116. *
  7117. * - `hostProtoViewRef`: {@link ProtoViewRef} Proto view to use in creating a view for this
  7118. * component.
  7119. * - `overrideSelector`: (optional) selector to use in locating the existing element to load
  7120. * the view into. If not specified use the selector in the component definition of the
  7121. * `hostProtoView`.
  7122. * - injector: {@link Injector} to use as parent injector for the view.
  7123. *
  7124. * See {@link AppViewManager#destroyRootHostView}.
  7125. *
  7126. * ## Example
  7127. *
  7128. * ```
  7129. * @ng.Component({
  7130. * selector: 'child-component'
  7131. * })
  7132. * @ng.View({
  7133. * template: 'Child'
  7134. * })
  7135. * class ChildComponent {
  7136. *
  7137. * }
  7138. *
  7139. * @ng.Component({
  7140. * selector: 'my-app'
  7141. * })
  7142. * @ng.View({
  7143. * template: `
  7144. * Parent (<some-component></some-component>)
  7145. * `
  7146. * })
  7147. * class MyApp {
  7148. * viewRef: ng.ViewRef;
  7149. *
  7150. * constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) {
  7151. * compiler.compileInHost(ChildComponent).then((protoView: ng.ProtoViewRef) => {
  7152. * this.viewRef = appViewManager.createRootHostView(protoView, 'some-component', null);
  7153. * })
  7154. * }
  7155. *
  7156. * onDestroy() {
  7157. * this.appViewManager.destroyRootHostView(this.viewRef);
  7158. * this.viewRef = null;
  7159. * }
  7160. * }
  7161. *
  7162. * ng.bootstrap(MyApp);
  7163. * ```
  7164. */
  7165. createRootHostView(hostProtoViewRef: ProtoViewRef, overrideSelector: string, injector: Injector): HostViewRef;
  7166. /**
  7167. * Remove the View created with {@link AppViewManager#createRootHostView}.
  7168. */
  7169. destroyRootHostView(hostViewRef: HostViewRef): void;
  7170. /**
  7171. * See {@link AppViewManager#destroyViewInContainer}.
  7172. */
  7173. createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number, templateRef: TemplateRef): ViewRef;
  7174. /**
  7175. * See {@link AppViewManager#destroyViewInContainer}.
  7176. */
  7177. createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number, protoViewRef: ProtoViewRef, imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef;
  7178. /**
  7179. * See {@link AppViewManager#createViewInContainer}.
  7180. */
  7181. destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number): void;
  7182. /**
  7183. * See {@link AppViewManager#detachViewInContainer}.
  7184. */
  7185. attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number, viewRef: ViewRef): ViewRef;
  7186. /**
  7187. * See {@link AppViewManager#attachViewInContainer}.
  7188. */
  7189. detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef;
  7190. }
  7191. /**
  7192. * An iterable and observable live list of components in the DOM.
  7193. *
  7194. * A QueryList contains a live list of child directives in the DOM of a directive.
  7195. * The directives are kept in depth-first pre-order traversal of the DOM.
  7196. *
  7197. * The `QueryList` is iterable, therefore it can be used in both javascript code with `for..of` loop
  7198. * as well as in template with `*ng-for="of"` directive.
  7199. *
  7200. * QueryList is updated as part of the change-detection cycle of a directive. Since change detection
  7201. * happens after construction of a directive, QueryList will always be empty when observed in the
  7202. * constructor.
  7203. *
  7204. *
  7205. * NOTE: In the future this class will implement an `Observable` interface. For now it uses a plain
  7206. * list of observable callbacks.
  7207. *
  7208. * # Example:
  7209. *
  7210. * Assume that `<tabs>` component would like to get a list its children which are `<pane>`
  7211. * components as shown in this example:
  7212. *
  7213. * ```html
  7214. * <tabs>
  7215. * <pane title="Overview">...</pane>
  7216. * <pane *ng-for="#o of objects" [title]="o.title">{{o.text}}</pane>
  7217. * </tabs>
  7218. * ```
  7219. *
  7220. * In the above example the list of `<tabs>` elements needs to get a list of `<pane>` elements so
  7221. * that it could render tabs with the correct titles and in the correct order.
  7222. *
  7223. * A possible solution would be for a `<pane>` to inject `<tabs>` component and then register itself
  7224. * with `<tabs>` component's on `hydrate` and deregister on `dehydrate` event. While a reasonable
  7225. * approach, this would only work partialy since `*ng-for` could rearrange the list of `<pane>`
  7226. * components which would not be reported to `<tabs>` component and thus the list of `<pane>`
  7227. * components would be out of sync with respect to the list of `<pane>` elements.
  7228. *
  7229. * A preferred solution is to inject a `QueryList` which is a live list of directives in the
  7230. * component`s light DOM.
  7231. *
  7232. * ```javascript
  7233. * @Component({
  7234. * selector: 'tabs'
  7235. * })
  7236. * @View({
  7237. * template: `
  7238. * <ul>
  7239. * <li *ng-for="#pane of panes">{{pane.title}}</li>
  7240. * </ul>
  7241. * <content></content>
  7242. * `
  7243. * })
  7244. * class Tabs {
  7245. * panes: QueryList<Pane>
  7246. *
  7247. * constructor(@Query(Pane) panes:QueryList<Pane>) {
  7248. * this.panes = panes;
  7249. * }
  7250. * }
  7251. *
  7252. * @Component({
  7253. * selector: 'pane',
  7254. * properties: ['title']
  7255. * })
  7256. * @View(...)
  7257. * class Pane {
  7258. * title:string;
  7259. * }
  7260. * ```
  7261. */
  7262. class QueryList<T> {
  7263. reset(newList: T[]): void;
  7264. add(obj: T): void;
  7265. fireCallbacks(): void;
  7266. onChange(callback: () => void): void;
  7267. removeCallback(callback: () => void): void;
  7268. toString(): string;
  7269. length: number;
  7270. first: T;
  7271. last: T;
  7272. map<U>(fn: (item: T) => U): U[];
  7273. }
  7274. /**
  7275. * Service for dynamically loading a Component into an arbitrary position in the internal Angular
  7276. * application tree.
  7277. */
  7278. class DynamicComponentLoader {
  7279. /**
  7280. * Loads a root component that is placed at the first element that matches the component's
  7281. * selector.
  7282. *
  7283. * - `typeOrBinding` `Type` \ {@link Binding} - representing the component to load.
  7284. * - `overrideSelector` (optional) selector to load the component at (or use
  7285. * `@Component.selector`) The selector can be anywhere (i.e. outside the current component.)
  7286. * - `injector` {@link Injector} - optional injector to use for the component.
  7287. *
  7288. * The loaded component receives injection normally as a hosted view.
  7289. *
  7290. *
  7291. * ## Example
  7292. *
  7293. * ```
  7294. * @ng.Component({
  7295. * selector: 'child-component'
  7296. * })
  7297. * @ng.View({
  7298. * template: 'Child'
  7299. * })
  7300. * class ChildComponent {
  7301. * }
  7302. *
  7303. *
  7304. *
  7305. * @ng.Component({
  7306. * selector: 'my-app'
  7307. * })
  7308. * @ng.View({
  7309. * template: `
  7310. * Parent (<child id="child"></child>)
  7311. * `
  7312. * })
  7313. * class MyApp {
  7314. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, injector: ng.Injector) {
  7315. * dynamicComponentLoader.loadAsRoot(ChildComponent, '#child', injector);
  7316. * }
  7317. * }
  7318. *
  7319. * ng.bootstrap(MyApp);
  7320. * ```
  7321. *
  7322. * Resulting DOM:
  7323. *
  7324. * ```
  7325. * <my-app>
  7326. * Parent (
  7327. * <child id="child">
  7328. * Child
  7329. * </child>
  7330. * )
  7331. * </my-app>
  7332. * ```
  7333. */
  7334. loadAsRoot(typeOrBinding: Type | Binding, overrideSelector: string, injector: Injector): Promise<ComponentRef>;
  7335. /**
  7336. * Loads a component into the component view of the provided ElementRef next to the element
  7337. * with the given name.
  7338. *
  7339. * The loaded component receives injection normally as a hosted view.
  7340. *
  7341. * ## Example
  7342. *
  7343. * ```
  7344. * @ng.Component({
  7345. * selector: 'child-component'
  7346. * })
  7347. * @ng.View({
  7348. * template: 'Child'
  7349. * })
  7350. * class ChildComponent {
  7351. * }
  7352. *
  7353. *
  7354. * @ng.Component({
  7355. * selector: 'my-app'
  7356. * })
  7357. * @ng.View({
  7358. * template: `
  7359. * Parent (<div #child></div>)
  7360. * `
  7361. * })
  7362. * class MyApp {
  7363. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
  7364. * dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
  7365. * }
  7366. * }
  7367. *
  7368. * ng.bootstrap(MyApp);
  7369. * ```
  7370. *
  7371. * Resulting DOM:
  7372. *
  7373. * ```
  7374. * <my-app>
  7375. * Parent (
  7376. * <div #child="" class="ng-binding"></div>
  7377. * <child-component class="ng-binding">Child</child-component>
  7378. * )
  7379. * </my-app>
  7380. * ```
  7381. */
  7382. loadIntoLocation(typeOrBinding: Type | Binding, hostLocation: ElementRef, anchorName: string, bindings?: ResolvedBinding[]): Promise<ComponentRef>;
  7383. /**
  7384. * Loads a component next to the provided ElementRef.
  7385. *
  7386. * The loaded component receives injection normally as a hosted view.
  7387. *
  7388. *
  7389. * ## Example
  7390. *
  7391. * ```
  7392. * @ng.Component({
  7393. * selector: 'child-component'
  7394. * })
  7395. * @ng.View({
  7396. * template: 'Child'
  7397. * })
  7398. * class ChildComponent {
  7399. * }
  7400. *
  7401. *
  7402. * @ng.Component({
  7403. * selector: 'my-app'
  7404. * })
  7405. * @ng.View({
  7406. * template: `Parent`
  7407. * })
  7408. * class MyApp {
  7409. * constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
  7410. * dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
  7411. * }
  7412. * }
  7413. *
  7414. * ng.bootstrap(MyApp);
  7415. * ```
  7416. *
  7417. * Resulting DOM:
  7418. *
  7419. * ```
  7420. * <my-app>Parent</my-app>
  7421. * <child-component>Child</child-component>
  7422. * ```
  7423. */
  7424. loadNextToLocation(typeOrBinding: Type | Binding, location: ElementRef, bindings?: ResolvedBinding[]): Promise<ComponentRef>;
  7425. }
  7426. /**
  7427. * Provides access to explicitly trigger change detection in an application.
  7428. *
  7429. * By default, `Zone` triggers change detection in Angular on each virtual machine (VM) turn. When
  7430. * testing, or in some
  7431. * limited application use cases, a developer can also trigger change detection with the
  7432. * `lifecycle.tick()` method.
  7433. *
  7434. * Each Angular application has a single `LifeCycle` instance.
  7435. *
  7436. * # Example
  7437. *
  7438. * This is a contrived example, since the bootstrap automatically runs inside of the `Zone`, which
  7439. * invokes
  7440. * `lifecycle.tick()` on your behalf.
  7441. *
  7442. * ```javascript
  7443. * bootstrap(MyApp).then((ref:ComponentRef) => {
  7444. * var lifeCycle = ref.injector.get(LifeCycle);
  7445. * var myApp = ref.instance;
  7446. *
  7447. * ref.doSomething();
  7448. * lifecycle.tick();
  7449. * });
  7450. * ```
  7451. */
  7452. class LifeCycle {
  7453. /**
  7454. * @private
  7455. */
  7456. registerWith(zone: NgZone, changeDetector?: ChangeDetector): void;
  7457. /**
  7458. * Invoke this method to explicitly process change detection and its side-effects.
  7459. *
  7460. * In development mode, `tick()` also performs a second change detection cycle to ensure that no
  7461. * further
  7462. * changes are detected. If additional changes are picked up during this second cycle, bindings
  7463. * in
  7464. * the app have
  7465. * side-effects that cannot be resolved in a single change detection pass. In this case, Angular
  7466. * throws an error,
  7467. * since an Angular application can only have one change detection pass during which all change
  7468. * detection must
  7469. * complete.
  7470. */
  7471. tick(): void;
  7472. }
  7473. /**
  7474. * Reference to the element.
  7475. *
  7476. * Represents an opaque reference to the underlying element. The element is a DOM ELement in
  7477. * a Browser, but may represent other types on other rendering platforms. In the browser the
  7478. * `ElementRef` can be sent to the web-worker. Web Workers can not have references to the
  7479. * DOM Elements.
  7480. */
  7481. class ElementRef implements RenderElementRef {
  7482. /**
  7483. * Reference to the {@link ViewRef} where the `ElementRef` is inside of.
  7484. */
  7485. parentView: ViewRef;
  7486. /**
  7487. * Index of the element inside the {@link ViewRef}.
  7488. *
  7489. * This is used internally by the Angular framework to locate elements.
  7490. */
  7491. boundElementIndex: number;
  7492. /**
  7493. * Index of the element inside the `RenderViewRef`.
  7494. *
  7495. * This is used internally by the Angular framework to locate elements.
  7496. */
  7497. renderBoundElementIndex: number;
  7498. renderView: RenderViewRef;
  7499. /**
  7500. * Returns the native Element implementation.
  7501. *
  7502. * In the browser this represents the DOM Element.
  7503. *
  7504. * The `nativeElement` can be used as an escape hatch when direct DOM manipulation is needed. Use
  7505. * this with caution, as it creates tight coupling between your application and the Browser, which
  7506. * will not work in WebWorkers.
  7507. *
  7508. * NOTE: This method will return null in the webworker scenario!
  7509. */
  7510. nativeElement: any;
  7511. }
  7512. /**
  7513. * Reference to a template within a component.
  7514. *
  7515. * Represents an opaque reference to the underlying template that can
  7516. * be instantiated using the {@link ViewContainerRef}.
  7517. */
  7518. class TemplateRef {
  7519. /**
  7520. * The location of the template
  7521. */
  7522. elementRef: ElementRef;
  7523. protoViewRef: ProtoViewRef;
  7524. /**
  7525. * Whether this template has a local variable with the given name
  7526. */
  7527. hasLocal(name: string): boolean;
  7528. }
  7529. /**
  7530. * A reference to an Angular View.
  7531. *
  7532. * A View is a fundamental building block of Application UI. A View is the smallest set of
  7533. * elements which are created and destroyed together. A View can change properties on the elements
  7534. * within the view, but it can not change the structure of those elements.
  7535. *
  7536. * To change structure of the elements, the Views can contain zero or more {@link ViewContainerRef}s
  7537. * which allow the views to be nested.
  7538. *
  7539. * ## Example
  7540. *
  7541. * Given this template
  7542. *
  7543. * ```
  7544. * Count: {{items.length}}
  7545. * <ul>
  7546. * <li *ng-for="var item of items">{{item}}</li>
  7547. * </ul>
  7548. * ```
  7549. *
  7550. * The above example we have two {@link ProtoViewRef}s:
  7551. *
  7552. * Outter {@link ProtoViewRef}:
  7553. * ```
  7554. * Count: {{items.length}}
  7555. * <ul>
  7556. * <template ng-for var-item [ng-for-of]="items"></template>
  7557. * </ul>
  7558. * ```
  7559. *
  7560. * Inner {@link ProtoViewRef}:
  7561. * ```
  7562. * <li>{{item}}</li>
  7563. * ```
  7564. *
  7565. * Notice that the original template is broken down into two separate {@link ProtoViewRef}s.
  7566. *
  7567. * The outter/inner {@link ProtoViewRef}s are then assembled into views like so:
  7568. *
  7569. * ```
  7570. * <!-- ViewRef: outer-0 -->
  7571. * Count: 2
  7572. * <ul>
  7573. * <template view-container-ref></template>
  7574. * <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
  7575. * <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
  7576. * </ul>
  7577. * <!-- /ViewRef: outer-0 -->
  7578. * ```
  7579. */
  7580. interface ViewRef extends HostViewRef {
  7581. /**
  7582. * Return `RenderViewRef`
  7583. */
  7584. render: RenderViewRef;
  7585. /**
  7586. * Return `RenderFragmentRef`
  7587. */
  7588. renderFragment: RenderFragmentRef;
  7589. /**
  7590. * Set local variable in a view.
  7591. *
  7592. * - `contextName` - Name of the local variable in a view.
  7593. * - `value` - Value for the local variable in a view.
  7594. */
  7595. setLocal(contextName: string, value: any): void;
  7596. }
  7597. interface HostViewRef {
  7598. }
  7599. /**
  7600. * A reference to an Angular ProtoView.
  7601. *
  7602. * A ProtoView is a reference to a template for easy creation of views.
  7603. * (See {@link AppViewManager#createViewInContainer `AppViewManager#createViewInContainer`} and
  7604. * {@link AppViewManager#createRootHostView `AppViewManager#createRootHostView`}).
  7605. *
  7606. * A `ProtoView` is a factory for creating `View`s.
  7607. *
  7608. * ## Example
  7609. *
  7610. * Given this template
  7611. *
  7612. * ```
  7613. * Count: {{items.length}}
  7614. * <ul>
  7615. * <li *ng-for="var item of items">{{item}}</li>
  7616. * </ul>
  7617. * ```
  7618. *
  7619. * The above example we have two {@link ProtoViewRef}s:
  7620. *
  7621. * Outter {@link ProtoViewRef}:
  7622. * ```
  7623. * Count: {{items.length}}
  7624. * <ul>
  7625. * <template ng-for var-item [ng-for-of]="items"></template>
  7626. * </ul>
  7627. * ```
  7628. *
  7629. * Inner {@link ProtoViewRef}:
  7630. * ```
  7631. * <li>{{item}}</li>
  7632. * ```
  7633. *
  7634. * Notice that the original template is broken down into two separate {@link ProtoViewRef}s.
  7635. */
  7636. interface ProtoViewRef {
  7637. }
  7638. /**
  7639. * A location where {@link ViewRef}s can be attached.
  7640. *
  7641. * A `ViewContainerRef` represents a location in a {@link ViewRef} where other child
  7642. * {@link ViewRef}s can be inserted. Adding and removing views is the only way of structurally
  7643. * changing the rendered DOM of the application.
  7644. */
  7645. interface ViewContainerRef {
  7646. viewManager: AppViewManager;
  7647. element: ElementRef;
  7648. /**
  7649. * Remove all {@link ViewRef}s at current location.
  7650. */
  7651. clear(): void;
  7652. /**
  7653. * Return a {@link ViewRef} at specific index.
  7654. */
  7655. get(index: number): ViewRef;
  7656. /**
  7657. * Returns number of {@link ViewRef}s currently attached at this location.
  7658. */
  7659. length: number;
  7660. /**
  7661. * Create and insert a {@link ViewRef} into the view-container.
  7662. *
  7663. * - `protoViewRef` (optional) {@link ProtoViewRef} - The `ProtoView` to use for creating
  7664. * `View` to be inserted at this location. If `ViewContainer` is created at a location
  7665. * of inline template, then `protoViewRef` is the `ProtoView` of the template.
  7666. * - `atIndex` (optional) `number` - location of insertion point. (Or at the end if unspecified.)
  7667. * - `context` (optional) {@link ElementRef} - Context (for expression evaluation) from the
  7668. * {@link ElementRef} location. (Or current context if unspecified.)
  7669. * - `bindings` (optional) Array of {@link ResolvedBinding} - Used for configuring
  7670. * `ElementInjector`.
  7671. *
  7672. * Returns newly created {@link ViewRef}.
  7673. */
  7674. createEmbeddedView(templateRef: TemplateRef, atIndex?: number): ViewRef;
  7675. createHostView(protoViewRef?: ProtoViewRef, atIndex?: number, dynamicallyCreatedBindings?: ResolvedBinding[]): HostViewRef;
  7676. /**
  7677. * Insert a {@link ViewRef} at specefic index.
  7678. *
  7679. * The index is location at which the {@link ViewRef} should be attached. If omitted it is
  7680. * inserted at the end.
  7681. *
  7682. * Returns the inserted {@link ViewRef}.
  7683. */
  7684. insert(viewRef: ViewRef, atIndex?: number): ViewRef;
  7685. /**
  7686. * Return the index of already inserted {@link ViewRef}.
  7687. */
  7688. indexOf(viewRef: ViewRef): number;
  7689. /**
  7690. * Remove a {@link ViewRef} at specific index.
  7691. *
  7692. * If the index is omitted last {@link ViewRef} is removed.
  7693. */
  7694. remove(atIndex?: number): void;
  7695. /**
  7696. * The method can be used together with insert to implement a view move, i.e.
  7697. * moving the dom nodes while the directives in the view stay intact.
  7698. */
  7699. detach(atIndex?: number): ViewRef;
  7700. }
  7701. /**
  7702. * Angular's reference to a component instance.
  7703. *
  7704. * `ComponentRef` represents a component instance lifecycle and meta information.
  7705. */
  7706. interface ComponentRef {
  7707. /**
  7708. * Location of the component host element.
  7709. */
  7710. location: ElementRef;
  7711. /**
  7712. * Instance of component.
  7713. */
  7714. instance: any;
  7715. /**
  7716. * Returns the host {@link ViewRef}.
  7717. */
  7718. hostView: HostViewRef;
  7719. /**
  7720. * Dispose of the component instance.
  7721. */
  7722. dispose(): void;
  7723. }
  7724. /**
  7725. * A wrapper around zones that lets you schedule tasks after it has executed a task.
  7726. *
  7727. * The wrapper maintains an "inner" and an "mount" `Zone`. The application code will executes
  7728. * in the "inner" zone unless `runOutsideAngular` is explicitely called.
  7729. *
  7730. * A typical application will create a singleton `NgZone`. The outer `Zone` is a fork of the root
  7731. * `Zone`. The default `onTurnDone` runs the Angular change detection.
  7732. */
  7733. class NgZone {
  7734. /**
  7735. * Sets the zone hook that is called just before Angular event turn starts.
  7736. * It is called once per browser event.
  7737. */
  7738. overrideOnTurnStart(onTurnStartFn: Function): void;
  7739. /**
  7740. * Sets the zone hook that is called immediately after Angular processes
  7741. * all pending microtasks.
  7742. */
  7743. overrideOnTurnDone(onTurnDoneFn: Function): void;
  7744. /**
  7745. * Sets the zone hook that is called immediately after the last turn in
  7746. * an event completes. At this point Angular will no longer attempt to
  7747. * sync the UI. Any changes to the data model will not be reflected in the
  7748. * DOM. `onEventDoneFn` is executed outside Angular zone.
  7749. *
  7750. * This hook is useful for validating application state (e.g. in a test).
  7751. */
  7752. overrideOnEventDone(onEventDoneFn: Function, opt_waitForAsync: boolean): void;
  7753. /**
  7754. * Sets the zone hook that is called when an error is uncaught in the
  7755. * Angular zone. The first argument is the error. The second argument is
  7756. * the stack trace.
  7757. */
  7758. overrideOnErrorHandler(errorHandlingFn: Function): void;
  7759. /**
  7760. * Runs `fn` in the inner zone and returns whatever it returns.
  7761. *
  7762. * In a typical app where the inner zone is the Angular zone, this allows one to make use of the
  7763. * Angular's auto digest mechanism.
  7764. *
  7765. * ```
  7766. * var zone: NgZone = [ref to the application zone];
  7767. *
  7768. * zone.run(() => {
  7769. * // the change detection will run after this function and the microtasks it enqueues have
  7770. * executed.
  7771. * });
  7772. * ```
  7773. */
  7774. run(fn: () => any): any;
  7775. /**
  7776. * Runs `fn` in the outer zone and returns whatever it returns.
  7777. *
  7778. * In a typical app where the inner zone is the Angular zone, this allows one to escape Angular's
  7779. * auto-digest mechanism.
  7780. *
  7781. * ```
  7782. * var zone: NgZone = [ref to the application zone];
  7783. *
  7784. * zone.runOutsideAngular(() => {
  7785. * element.onClick(() => {
  7786. * // Clicking on the element would not trigger the change detection
  7787. * });
  7788. * });
  7789. * ```
  7790. */
  7791. runOutsideAngular(fn: () => any): any;
  7792. }
  7793. class Observable {
  7794. observer(generator: any): Object;
  7795. }
  7796. /**
  7797. * Use Rx.Observable but provides an adapter to make it work as specified here:
  7798. * https://github.com/jhusain/observable-spec
  7799. *
  7800. * Once a reference implementation of the spec is available, switch to it.
  7801. */
  7802. class EventEmitter extends Observable {
  7803. observer(generator: any): Rx.IDisposable;
  7804. toRx(): Rx.Observable<any>;
  7805. next(value: any): void;
  7806. throw(error: any): void;
  7807. return(value?: any): void;
  7808. }
  7809. /**
  7810. * A parameter metadata that specifies a dependency.
  7811. *
  7812. * ```
  7813. * class AComponent {
  7814. * constructor(@Inject(MyService) aService:MyService) {}
  7815. * }
  7816. * ```
  7817. */
  7818. class InjectMetadata {
  7819. token: any;
  7820. toString(): string;
  7821. }
  7822. /**
  7823. * A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if
  7824. * the dependency is not found.
  7825. *
  7826. * ```
  7827. * class AComponent {
  7828. * constructor(@Optional() aService:MyService) {
  7829. * this.aService = aService;
  7830. * }
  7831. * }
  7832. * ```
  7833. */
  7834. class OptionalMetadata {
  7835. toString(): string;
  7836. }
  7837. /**
  7838. * A marker metadata that marks a class as available to `Injector` for creation. Used by tooling
  7839. * for generating constructor stubs.
  7840. *
  7841. * ```
  7842. * class NeedsService {
  7843. * constructor(svc:UsefulService) {}
  7844. * }
  7845. *
  7846. * @Injectable
  7847. * class UsefulService {}
  7848. * ```
  7849. */
  7850. class InjectableMetadata {
  7851. }
  7852. /**
  7853. * Specifies that an injector should retrieve a dependency from itself.
  7854. *
  7855. * ## Example
  7856. *
  7857. * ```
  7858. * class Dependency {
  7859. * }
  7860. *
  7861. * class NeedsDependency {
  7862. * constructor(public @Self() dependency:Dependency) {}
  7863. * }
  7864. *
  7865. * var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]);
  7866. * var nd = inj.get(NeedsDependency);
  7867. * expect(nd.dependency).toBeAnInstanceOf(Dependency);
  7868. * ```
  7869. */
  7870. class SelfMetadata {
  7871. toString(): string;
  7872. }
  7873. /**
  7874. * Specifies that an injector should retrieve a dependency from any injector until reaching the
  7875. * closest host.
  7876. *
  7877. * ## Example
  7878. *
  7879. * ```
  7880. * class Dependency {
  7881. * }
  7882. *
  7883. * class NeedsDependency {
  7884. * constructor(public @Host() dependency:Dependency) {}
  7885. * }
  7886. *
  7887. * var parent = Injector.resolveAndCreate([
  7888. * bind(Dependency).toClass(HostDependency)
  7889. * ]);
  7890. * var child = parent.resolveAndCreateChild([]);
  7891. * var grandChild = child.resolveAndCreateChild([NeedsDependency, Depedency]);
  7892. * var nd = grandChild.get(NeedsDependency);
  7893. * expect(nd.dependency).toBeAnInstanceOf(HostDependency);
  7894. * ```
  7895. */
  7896. class HostMetadata {
  7897. toString(): string;
  7898. }
  7899. /**
  7900. * Specifies that the dependency resolution should start from the parent injector.
  7901. *
  7902. * ## Example
  7903. *
  7904. *
  7905. * ```
  7906. * class Service {}
  7907. *
  7908. * class ParentService implements Service {
  7909. * }
  7910. *
  7911. * class ChildService implements Service {
  7912. * constructor(public @SkipSelf() parentService:Service) {}
  7913. * }
  7914. *
  7915. * var parent = Injector.resolveAndCreate([
  7916. * bind(Service).toClass(ParentService)
  7917. * ]);
  7918. * var child = parent.resolveAndCreateChild([
  7919. * bind(Service).toClass(ChildSerice)
  7920. * ]);
  7921. * var s = child.get(Service);
  7922. * expect(s).toBeAnInstanceOf(ChildService);
  7923. * expect(s.parentService).toBeAnInstanceOf(ParentService);
  7924. * ```
  7925. */
  7926. class SkipSelfMetadata {
  7927. toString(): string;
  7928. }
  7929. /**
  7930. * `DependencyMetadata is used by the framework to extend DI.
  7931. *
  7932. * Only metadata implementing `DependencyMetadata` are added to the list of dependency
  7933. * properties.
  7934. *
  7935. * For example:
  7936. *
  7937. * ```
  7938. * class Exclude extends DependencyMetadata {}
  7939. * class NotDependencyProperty {}
  7940. *
  7941. * class AComponent {
  7942. * constructor(@Exclude @NotDependencyProperty aService:AService) {}
  7943. * }
  7944. * ```
  7945. *
  7946. * will create the following dependency:
  7947. *
  7948. * ```
  7949. * new Dependency(Key.get(AService), [new Exclude()])
  7950. * ```
  7951. *
  7952. * The framework can use `new Exclude()` to handle the `aService` dependency
  7953. * in a specific way.
  7954. */
  7955. class DependencyMetadata {
  7956. token: any;
  7957. }
  7958. /**
  7959. * Allows to refer to references which are not yet defined.
  7960. *
  7961. * This situation arises when the key which we need te refer to for the purposes of DI is declared,
  7962. * but not yet defined.
  7963. *
  7964. * ## Example:
  7965. *
  7966. * ```
  7967. * class Door {
  7968. * // Incorrect way to refer to a reference which is defined later.
  7969. * // This fails because `Lock` is undefined at this point.
  7970. * constructor(lock:Lock) { }
  7971. *
  7972. * // Correct way to refer to a reference which is defined later.
  7973. * // The reference needs to be captured in a closure.
  7974. * constructor(@Inject(forwardRef(() => Lock)) lock:Lock) { }
  7975. * }
  7976. *
  7977. * // Only at this point the lock is defined.
  7978. * class Lock {
  7979. * }
  7980. * ```
  7981. */
  7982. function forwardRef(forwardRefFn: ForwardRefFn) : Type ;
  7983. /**
  7984. * Lazily retrieve the reference value.
  7985. *
  7986. * See: {@link forwardRef}
  7987. */
  7988. function resolveForwardRef(type: any) : any ;
  7989. interface ForwardRefFn {
  7990. (): any;
  7991. }
  7992. /**
  7993. * A dependency injection container used for resolving dependencies.
  7994. *
  7995. * An `Injector` is a replacement for a `new` operator, which can automatically resolve the
  7996. * constructor dependencies.
  7997. * In typical use, application code asks for the dependencies in the constructor and they are
  7998. * resolved by the `Injector`.
  7999. *
  8000. * ## Example:
  8001. *
  8002. * Suppose that we want to inject an `Engine` into class `Car`, we would define it like this:
  8003. *
  8004. * ```javascript
  8005. * class Engine {
  8006. * }
  8007. *
  8008. * class Car {
  8009. * constructor(@Inject(Engine) engine) {
  8010. * }
  8011. * }
  8012. *
  8013. * ```
  8014. *
  8015. * Next we need to write the code that creates and instantiates the `Injector`. We then ask for the
  8016. * `root` object, `Car`, so that the `Injector` can recursively build all of that object's
  8017. * dependencies.
  8018. *
  8019. * ```javascript
  8020. * main() {
  8021. * var injector = Injector.resolveAndCreate([Car, Engine]);
  8022. *
  8023. * // Get a reference to the `root` object, which will recursively instantiate the tree.
  8024. * var car = injector.get(Car);
  8025. * }
  8026. * ```
  8027. * Notice that we don't use the `new` operator because we explicitly want to have the `Injector`
  8028. * resolve all of the object's dependencies automatically.
  8029. */
  8030. class Injector {
  8031. /**
  8032. * Turns a list of binding definitions into an internal resolved list of resolved bindings.
  8033. *
  8034. * A resolution is a process of flattening multiple nested lists and converting individual
  8035. * bindings into a list of {@link ResolvedBinding}s. The resolution can be cached by `resolve`
  8036. * for the {@link Injector} for performance-sensitive code.
  8037. *
  8038. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  8039. * recursive list of more bindings.
  8040. *
  8041. * The returned list is sparse, indexed by `id` for the {@link Key}. It is generally not useful to
  8042. * application code
  8043. * other than for passing it to {@link Injector} functions that require resolved binding lists,
  8044. * such as
  8045. * `fromResolvedBindings` and `createChildFromResolved`.
  8046. */
  8047. static resolve(bindings: Array<Type | Binding | any[]>): ResolvedBinding[];
  8048. /**
  8049. * Resolves bindings and creates an injector based on those bindings. This function is slower than
  8050. * the corresponding `fromResolvedBindings` because it needs to resolve bindings first. See
  8051. * `resolve`
  8052. * for the {@link Injector}.
  8053. *
  8054. * Prefer `fromResolvedBindings` in performance-critical code that creates lots of injectors.
  8055. *
  8056. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  8057. * recursive list of more
  8058. * bindings.
  8059. * @param `depProvider`
  8060. */
  8061. static resolveAndCreate(bindings: Array<Type | Binding | any[]>, depProvider?: DependencyProvider): Injector;
  8062. /**
  8063. * Creates an injector from previously resolved bindings. This bypasses resolution and flattening.
  8064. * This API is the recommended way to construct injectors in performance-sensitive parts.
  8065. *
  8066. * @param `bindings` A sparse list of {@link ResolvedBinding}s. See `resolve` for the
  8067. * {@link Injector}.
  8068. * @param `depProvider`
  8069. */
  8070. static fromResolvedBindings(bindings: ResolvedBinding[], depProvider?: DependencyProvider): Injector;
  8071. /**
  8072. * Returns debug information about the injector.
  8073. *
  8074. * This information is included into exceptions thrown by the injector.
  8075. */
  8076. debugContext(): any;
  8077. /**
  8078. * Retrieves an instance from the injector.
  8079. *
  8080. * @param `token`: usually the `Type` of an object. (Same as the token used while setting up a
  8081. * binding).
  8082. * @returns an instance represented by the token. Throws if not found.
  8083. */
  8084. get(token: any): any;
  8085. /**
  8086. * Retrieves an instance from the injector.
  8087. *
  8088. * @param `token`: usually a `Type`. (Same as the token used while setting up a binding).
  8089. * @returns an instance represented by the token. Returns `null` if not found.
  8090. */
  8091. getOptional(token: any): any;
  8092. /**
  8093. * Retrieves an instance from the injector.
  8094. *
  8095. * @param `index`: index of an instance.
  8096. * @returns an instance represented by the index. Throws if not found.
  8097. */
  8098. getAt(index: number): any;
  8099. /**
  8100. * Direct parent of this injector.
  8101. */
  8102. parent: Injector;
  8103. /**
  8104. * Internal. Do not use.
  8105. *
  8106. * We return `any` not to export the InjectorStrategy type.
  8107. */
  8108. internalStrategy: any;
  8109. /**
  8110. * Creates a child injector and loads a new set of bindings into it.
  8111. *
  8112. * A resolution is a process of flattening multiple nested lists and converting individual
  8113. * bindings into a list of {@link ResolvedBinding}s. The resolution can be cached by `resolve`
  8114. * for the {@link Injector} for performance-sensitive code.
  8115. *
  8116. * @param `bindings` can be a list of `Type`, {@link Binding}, {@link ResolvedBinding}, or a
  8117. * recursive list of more bindings.
  8118. * @param `depProvider`
  8119. */
  8120. resolveAndCreateChild(bindings: Array<Type | Binding | any[]>, depProvider?: DependencyProvider): Injector;
  8121. /**
  8122. * Creates a child injector and loads a new set of {@link ResolvedBinding}s into it.
  8123. *
  8124. * @param `bindings`: A sparse list of {@link ResolvedBinding}s.
  8125. * See `resolve` for the {@link Injector}.
  8126. * @param `depProvider`
  8127. * @returns a new child {@link Injector}.
  8128. */
  8129. createChildFromResolved(bindings: ResolvedBinding[], depProvider?: DependencyProvider): Injector;
  8130. /**
  8131. * Resolves a binding and instantiates an object in the context of the injector.
  8132. *
  8133. * @param `binding`: either a type or a binding.
  8134. * @returns an object created using binding.
  8135. */
  8136. resolveAndInstantiate(binding: Type | Binding): any;
  8137. /**
  8138. * Instantiates an object using a resolved bindin in the context of the injector.
  8139. *
  8140. * @param `binding`: a resolved binding
  8141. * @returns an object created using binding.
  8142. */
  8143. instantiateResolved(binding: ResolvedBinding): any;
  8144. displayName: string;
  8145. toString(): string;
  8146. }
  8147. class ProtoInjector {
  8148. numberOfBindings: number;
  8149. getBindingAtIndex(index: number): any;
  8150. }
  8151. class BindingWithVisibility {
  8152. binding: ResolvedBinding;
  8153. visibility: Visibility;
  8154. getKeyId(): number;
  8155. }
  8156. /**
  8157. * Used to provide dependencies that cannot be easily expressed as bindings.
  8158. */
  8159. interface DependencyProvider {
  8160. getDependency(injector: Injector, binding: ResolvedBinding, dependency: Dependency): any;
  8161. }
  8162. enum Visibility {
  8163. Public,
  8164. Private,
  8165. PublicAndPrivate
  8166. }
  8167. const UNDEFINED : Object ;
  8168. /**
  8169. * Describes how_ the {@link Injector} should instantiate a given token.
  8170. *
  8171. * See {@link bind}.
  8172. *
  8173. * ## Example
  8174. *
  8175. * ```javascript
  8176. * var injector = Injector.resolveAndCreate([
  8177. * new Binding(String, { toValue: 'Hello' })
  8178. * ]);
  8179. *
  8180. * expect(injector.get(String)).toEqual('Hello');
  8181. * ```
  8182. */
  8183. class Binding {
  8184. /**
  8185. * Token used when retrieving this binding. Usually the `Type`.
  8186. */
  8187. token: any;
  8188. /**
  8189. * Binds an interface to an implementation / subclass.
  8190. *
  8191. * ## Example
  8192. *
  8193. * Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy
  8194. * comparison.
  8195. *
  8196. * ```javascript
  8197. *
  8198. * class Vehicle {}
  8199. *
  8200. * class Car extends Vehicle {}
  8201. *
  8202. * var injectorClass = Injector.resolveAndCreate([
  8203. * Car,
  8204. * new Binding(Vehicle, { toClass: Car })
  8205. * ]);
  8206. * var injectorAlias = Injector.resolveAndCreate([
  8207. * Car,
  8208. * new Binding(Vehicle, { toAlias: Car })
  8209. * ]);
  8210. *
  8211. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  8212. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  8213. *
  8214. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  8215. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  8216. * ```
  8217. */
  8218. toClass: Type;
  8219. /**
  8220. * Binds a key to a value.
  8221. *
  8222. * ## Example
  8223. *
  8224. * ```javascript
  8225. * var injector = Injector.resolveAndCreate([
  8226. * new Binding(String, { toValue: 'Hello' })
  8227. * ]);
  8228. *
  8229. * expect(injector.get(String)).toEqual('Hello');
  8230. * ```
  8231. */
  8232. toValue: any;
  8233. /**
  8234. * Binds a key to the alias for an existing key.
  8235. *
  8236. * An alias means that {@link Injector} returns the same instance as if the alias token was used.
  8237. * This is in contrast to `toClass` where a separate instance of `toClass` is returned.
  8238. *
  8239. * ## Example
  8240. *
  8241. * Becuse `toAlias` and `toClass` are often confused the example contains both use cases for easy
  8242. * comparison.
  8243. *
  8244. * ```javascript
  8245. *
  8246. * class Vehicle {}
  8247. *
  8248. * class Car extends Vehicle {}
  8249. *
  8250. * var injectorAlias = Injector.resolveAndCreate([
  8251. * Car,
  8252. * new Binding(Vehicle, { toAlias: Car })
  8253. * ]);
  8254. * var injectorClass = Injector.resolveAndCreate([
  8255. * Car,
  8256. * new Binding(Vehicle, { toClass: Car })
  8257. * ]);
  8258. *
  8259. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  8260. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  8261. *
  8262. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  8263. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  8264. * ```
  8265. */
  8266. toAlias: any;
  8267. /**
  8268. * Binds a key to a function which computes the value.
  8269. *
  8270. * ## Example
  8271. *
  8272. * ```javascript
  8273. * var injector = Injector.resolveAndCreate([
  8274. * new Binding(Number, { toFactory: () => { return 1+2; }}),
  8275. * new Binding(String, { toFactory: (value) => { return "Value: " + value; },
  8276. * dependencies: [Number] })
  8277. * ]);
  8278. *
  8279. * expect(injector.get(Number)).toEqual(3);
  8280. * expect(injector.get(String)).toEqual('Value: 3');
  8281. * ```
  8282. */
  8283. toFactory: Function;
  8284. /**
  8285. * Used in conjunction with `toFactory` and specifies a set of dependencies
  8286. * (as `token`s) which should be injected into the factory function.
  8287. *
  8288. * ## Example
  8289. *
  8290. * ```javascript
  8291. * var injector = Injector.resolveAndCreate([
  8292. * new Binding(Number, { toFactory: () => { return 1+2; }}),
  8293. * new Binding(String, { toFactory: (value) => { return "Value: " + value; },
  8294. * dependencies: [Number] })
  8295. * ]);
  8296. *
  8297. * expect(injector.get(Number)).toEqual(3);
  8298. * expect(injector.get(String)).toEqual('Value: 3');
  8299. * ```
  8300. */
  8301. dependencies: any[];
  8302. /**
  8303. * Converts the {@link Binding} into {@link ResolvedBinding}.
  8304. *
  8305. * {@link Injector} internally only uses {@link ResolvedBinding}, {@link Binding} contains
  8306. * convenience binding syntax.
  8307. */
  8308. resolve(): ResolvedBinding;
  8309. }
  8310. /**
  8311. * Helper class for the {@link bind} function.
  8312. */
  8313. class BindingBuilder {
  8314. token: any;
  8315. /**
  8316. * Binds an interface to an implementation / subclass.
  8317. *
  8318. * ## Example
  8319. *
  8320. * Because `toAlias` and `toClass` are often confused, the example contains both use cases for
  8321. * easy comparison.
  8322. *
  8323. * ```javascript
  8324. *
  8325. * class Vehicle {}
  8326. *
  8327. * class Car extends Vehicle {}
  8328. *
  8329. * var injectorClass = Injector.resolveAndCreate([
  8330. * Car,
  8331. * bind(Vehicle).toClass(Car)
  8332. * ]);
  8333. * var injectorAlias = Injector.resolveAndCreate([
  8334. * Car,
  8335. * bind(Vehicle).toAlias(Car)
  8336. * ]);
  8337. *
  8338. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  8339. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  8340. *
  8341. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  8342. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  8343. * ```
  8344. */
  8345. toClass(type: Type): Binding;
  8346. /**
  8347. * Binds a key to a value.
  8348. *
  8349. * ## Example
  8350. *
  8351. * ```javascript
  8352. * var injector = Injector.resolveAndCreate([
  8353. * bind(String).toValue('Hello')
  8354. * ]);
  8355. *
  8356. * expect(injector.get(String)).toEqual('Hello');
  8357. * ```
  8358. */
  8359. toValue(value: any): Binding;
  8360. /**
  8361. * Binds a key to the alias for an existing key.
  8362. *
  8363. * An alias means that we will return the same instance as if the alias token was used. (This is
  8364. * in contrast to `toClass` where a separate instance of `toClass` will be returned.)
  8365. *
  8366. * ## Example
  8367. *
  8368. * Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy
  8369. * comparison.
  8370. *
  8371. * ```javascript
  8372. *
  8373. * class Vehicle {}
  8374. *
  8375. * class Car extends Vehicle {}
  8376. *
  8377. * var injectorAlias = Injector.resolveAndCreate([
  8378. * Car,
  8379. * bind(Vehicle).toAlias(Car)
  8380. * ]);
  8381. * var injectorClass = Injector.resolveAndCreate([
  8382. * Car,
  8383. * bind(Vehicle).toClass(Car)
  8384. * ]);
  8385. *
  8386. * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
  8387. * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
  8388. *
  8389. * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
  8390. * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
  8391. * ```
  8392. */
  8393. toAlias(aliasToken: /*Type*/ any): Binding;
  8394. /**
  8395. * Binds a key to a function which computes the value.
  8396. *
  8397. * ## Example
  8398. *
  8399. * ```javascript
  8400. * var injector = Injector.resolveAndCreate([
  8401. * bind(Number).toFactory(() => { return 1+2; }),
  8402. * bind(String).toFactory((v) => { return "Value: " + v; }, [Number])
  8403. * ]);
  8404. *
  8405. * expect(injector.get(Number)).toEqual(3);
  8406. * expect(injector.get(String)).toEqual('Value: 3');
  8407. * ```
  8408. */
  8409. toFactory(factoryFunction: Function, dependencies?: any[]): Binding;
  8410. }
  8411. /**
  8412. * An internal resolved representation of a {@link Binding} used by the {@link Injector}.
  8413. *
  8414. * A {@link Binding} is resolved when it has a factory function. Binding to a class, alias, or
  8415. * value, are just convenience methods, as {@link Injector} only operates on calling factory
  8416. * functions.
  8417. */
  8418. class ResolvedBinding {
  8419. /**
  8420. * A key, usually a `Type`.
  8421. */
  8422. key: Key;
  8423. /**
  8424. * Factory function which can return an instance of an object represented by a key.
  8425. */
  8426. factory: Function;
  8427. /**
  8428. * Arguments (dependencies) to the `factory` function.
  8429. */
  8430. dependencies: Dependency[];
  8431. }
  8432. /**
  8433. * @private
  8434. */
  8435. class Dependency {
  8436. static fromKey(key: Key): Dependency;
  8437. key: Key;
  8438. optional: boolean;
  8439. lowerBoundVisibility: any;
  8440. upperBoundVisibility: any;
  8441. properties: any[];
  8442. }
  8443. /**
  8444. * Provides an API for imperatively constructing {@link Binding}s.
  8445. *
  8446. * This is only relevant for JavaScript. See {@link BindingBuilder}.
  8447. *
  8448. * ## Example
  8449. *
  8450. * ```javascript
  8451. * bind(MyInterface).toClass(MyClass)
  8452. *
  8453. * ```
  8454. */
  8455. function bind(token: any) : BindingBuilder ;
  8456. /**
  8457. * A unique object used for retrieving items from the {@link Injector}.
  8458. *
  8459. * Keys have:
  8460. * - a system-wide unique `id`.
  8461. * - a `token`, usually the `Type` of the instance.
  8462. *
  8463. * Keys are used internally by the {@link Injector} because their system-wide unique `id`s allow the
  8464. * injector to index in arrays rather than looking up items in maps.
  8465. */
  8466. class Key {
  8467. /**
  8468. * Retrieves a `Key` for a token.
  8469. */
  8470. static get(token: Object): Key;
  8471. /**
  8472. * @returns the number of keys registered in the system.
  8473. */
  8474. static numberOfKeys: number;
  8475. token: Object;
  8476. id: number;
  8477. displayName: string;
  8478. }
  8479. /**
  8480. * @private
  8481. */
  8482. class KeyRegistry {
  8483. get(token: Object): Key;
  8484. numberOfKeys: number;
  8485. }
  8486. /**
  8487. * Type literals is a Dart-only feature. This is here only so we can x-compile
  8488. * to multiple languages.
  8489. */
  8490. class TypeLiteral {
  8491. type: any;
  8492. }
  8493. /**
  8494. * Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the
  8495. * {@link Injector} does not have a {@link Binding} for {@link Key}.
  8496. */
  8497. class NoBindingError extends AbstractBindingError {
  8498. }
  8499. /**
  8500. * Base class for all errors arising from misconfigured bindings.
  8501. */
  8502. class AbstractBindingError extends BaseException {
  8503. name: string;
  8504. message: string;
  8505. keys: Key[];
  8506. injectors: Injector[];
  8507. constructResolvingMessage: Function;
  8508. addKey(injector: Injector, key: Key): void;
  8509. context: any;
  8510. toString(): string;
  8511. }
  8512. /**
  8513. * Thrown when dependencies form a cycle.
  8514. *
  8515. * ## Example:
  8516. *
  8517. * ```javascript
  8518. * class A {
  8519. * constructor(b:B) {}
  8520. * }
  8521. * class B {
  8522. * constructor(a:A) {}
  8523. * }
  8524. * ```
  8525. *
  8526. * Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed.
  8527. */
  8528. class CyclicDependencyError extends AbstractBindingError {
  8529. }
  8530. /**
  8531. * Thrown when a constructing type returns with an Error.
  8532. *
  8533. * The `InstantiationError` class contains the original error plus the dependency graph which caused
  8534. * this object to be instantiated.
  8535. */
  8536. class InstantiationError extends AbstractBindingError {
  8537. causeKey: Key;
  8538. }
  8539. /**
  8540. * Thrown when an object other then {@link Binding} (or `Type`) is passed to {@link Injector}
  8541. * creation.
  8542. */
  8543. class InvalidBindingError extends BaseException {
  8544. message: string;
  8545. toString(): string;
  8546. }
  8547. /**
  8548. * Thrown when the class has no annotation information.
  8549. *
  8550. * Lack of annotation information prevents the {@link Injector} from determining which dependencies
  8551. * need to be injected into the constructor.
  8552. */
  8553. class NoAnnotationError extends BaseException {
  8554. name: string;
  8555. message: string;
  8556. toString(): string;
  8557. }
  8558. /**
  8559. * Thrown when getting an object by index.
  8560. */
  8561. class OutOfBoundsError extends BaseException {
  8562. message: string;
  8563. toString(): string;
  8564. }
  8565. class OpaqueToken {
  8566. toString(): string;
  8567. }
  8568. /**
  8569. * Factory for creating {@link InjectMetadata}.
  8570. */
  8571. interface InjectFactory {
  8572. new(token: any): InjectMetadata;
  8573. (token: any): any;
  8574. }
  8575. /**
  8576. * Factory for creating {@link OptionalMetadata}.
  8577. */
  8578. interface OptionalFactory {
  8579. new(): OptionalMetadata;
  8580. (): any;
  8581. }
  8582. /**
  8583. * Factory for creating {@link InjectableMetadata}.
  8584. */
  8585. interface InjectableFactory {
  8586. new(): InjectableMetadata;
  8587. (): any;
  8588. }
  8589. /**
  8590. * Factory for creating {@link SelfMetadata}.
  8591. */
  8592. interface SelfFactory {
  8593. new(): SelfMetadata;
  8594. (): any;
  8595. }
  8596. /**
  8597. * Factory for creating {@link HostMetadata}.
  8598. */
  8599. interface HostFactory {
  8600. new(): HostMetadata;
  8601. (): any;
  8602. }
  8603. /**
  8604. * Factory for creating {@link SkipSelfMetadata}.
  8605. */
  8606. interface SkipSelfFactory {
  8607. new(): SkipSelfMetadata;
  8608. (): any;
  8609. }
  8610. /**
  8611. * Factory for creating {@link InjectMetadata}.
  8612. */
  8613. var Inject : InjectFactory ;
  8614. /**
  8615. * Factory for creating {@link OptionalMetadata}.
  8616. */
  8617. var Optional : OptionalFactory ;
  8618. /**
  8619. * Factory for creating {@link InjectableMetadata}.
  8620. */
  8621. var Injectable : InjectableFactory ;
  8622. /**
  8623. * Factory for creating {@link SelfMetadata}.
  8624. */
  8625. var Self : SelfFactory ;
  8626. /**
  8627. * Factory for creating {@link HostMetadata}.
  8628. */
  8629. var Host : HostFactory ;
  8630. /**
  8631. * Factory for creating {@link SkipSelfMetadata}.
  8632. */
  8633. var SkipSelf : SkipSelfFactory ;
  8634. /**
  8635. * A collection of the Angular core directives that are likely to be used in each and every Angular
  8636. * application.
  8637. *
  8638. * This collection can be used to quickly enumerate all the built-in directives in the `@View`
  8639. * annotation. For example,
  8640. * instead of writing:
  8641. *
  8642. * ```
  8643. * import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from 'angular2/angular2';
  8644. * import {OtherDirective} from 'myDirectives';
  8645. *
  8646. * @Component({
  8647. * selector: 'my-component'
  8648. * })
  8649. * @View({
  8650. * templateUrl: 'myComponent.html',
  8651. * directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, OtherDirective]
  8652. * })
  8653. * export class MyComponent {
  8654. * ...
  8655. * }
  8656. * ```
  8657. * one could import all the core directives at once:
  8658. *
  8659. * ```
  8660. * import {CORE_DIRECTIVES} from 'angular2/angular2';
  8661. * import {OtherDirective} from 'myDirectives';
  8662. *
  8663. * @Component({
  8664. * selector: 'my-component'
  8665. * })
  8666. * @View({
  8667. * templateUrl: 'myComponent.html',
  8668. * directives: [CORE_DIRECTIVES, OtherDirective]
  8669. * })
  8670. * export class MyComponent {
  8671. * ...
  8672. * }
  8673. * ```
  8674. */
  8675. const CORE_DIRECTIVES : Type[] ;
  8676. /**
  8677. * Adds and removes CSS classes based on an {expression} value.
  8678. *
  8679. * The result of expression is used to add and remove CSS classes using the following logic,
  8680. * based on expression's value type:
  8681. * - {string} - all the CSS classes (space - separated) are added
  8682. * - {Array} - all the CSS classes (Array elements) are added
  8683. * - {Object} - each key corresponds to a CSS class name while values
  8684. * are interpreted as {boolean} expression. If a given expression
  8685. * evaluates to {true} a corresponding CSS class is added - otherwise
  8686. * it is removed.
  8687. *
  8688. * # Example:
  8689. *
  8690. * ```
  8691. * <div class="message" [ng-class]="{error: errorCount > 0}">
  8692. * Please check errors.
  8693. * </div>
  8694. * ```
  8695. */
  8696. class NgClass {
  8697. initialClasses: any;
  8698. rawClass: any;
  8699. doCheck(): void;
  8700. onDestroy(): void;
  8701. }
  8702. /**
  8703. * The `NgFor` directive instantiates a template once per item from an iterable. The context for
  8704. * each instantiated template inherits from the outer context with the given loop variable set
  8705. * to the current item from the iterable.
  8706. *
  8707. * It is possible to alias the `index` to a local variable that will be set to the current loop
  8708. * iteration in the template context.
  8709. *
  8710. * When the contents of the iterator changes, `NgFor` makes the corresponding changes to the DOM:
  8711. *
  8712. * * When an item is added, a new instance of the template is added to the DOM.
  8713. * * When an item is removed, its template instance is removed from the DOM.
  8714. * * When items are reordered, their respective templates are reordered in the DOM.
  8715. *
  8716. * # Example
  8717. *
  8718. * ```
  8719. * <ul>
  8720. * <li *ng-for="#error of errors; #i = index">
  8721. * Error {{i}} of {{errors.length}}: {{error.message}}
  8722. * </li>
  8723. * </ul>
  8724. * ```
  8725. *
  8726. * # Syntax
  8727. *
  8728. * - `<li *ng-for="#item of items; #i = index">...</li>`
  8729. * - `<li template="ng-for #item of items; #i = index">...</li>`
  8730. * - `<template ng-for #item [ng-for-of]="items" #i="index"><li>...</li></template>`
  8731. */
  8732. class NgFor {
  8733. static bulkRemove(tuples: RecordViewTuple[], viewContainer: ViewContainerRef): RecordViewTuple[];
  8734. static bulkInsert(tuples: RecordViewTuple[], viewContainer: ViewContainerRef, templateRef: TemplateRef): RecordViewTuple[];
  8735. viewContainer: ViewContainerRef;
  8736. templateRef: TemplateRef;
  8737. iterableDiffers: IterableDiffers;
  8738. cdr: ChangeDetectorRef;
  8739. ngForOf: any;
  8740. doCheck(): void;
  8741. }
  8742. class RecordViewTuple {
  8743. view: ViewRef;
  8744. record: any;
  8745. }
  8746. /**
  8747. * Removes or recreates a portion of the DOM tree based on an {expression}.
  8748. *
  8749. * If the expression assigned to `ng-if` evaluates to a false value then the element
  8750. * is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.
  8751. *
  8752. * # Example:
  8753. *
  8754. * ```
  8755. * <div *ng-if="errorCount > 0" class="error">
  8756. * <!-- Error message displayed when the errorCount property on the current context is greater
  8757. * than 0. -->
  8758. * {{errorCount}} errors detected
  8759. * </div>
  8760. * ```
  8761. *
  8762. * # Syntax
  8763. *
  8764. * - `<div *ng-if="condition">...</div>`
  8765. * - `<div template="ng-if condition">...</div>`
  8766. * - `<template [ng-if]="condition"><div>...</div></template>`
  8767. */
  8768. class NgIf {
  8769. ngIf: any;
  8770. }
  8771. /**
  8772. * The `NgNonBindable` directive tells Angular not to compile or bind the contents of the current
  8773. * DOM element. This is useful if the element contains what appears to be Angular directives and
  8774. * bindings but which should be ignored by Angular. This could be the case if you have a site that
  8775. * displays snippets of code, for instance.
  8776. *
  8777. * Example:
  8778. *
  8779. * ```
  8780. * <div>Normal: {{1 + 2}}</div> // output "Normal: 3"
  8781. * <div ng-non-bindable>Ignored: {{1 + 2}}</div> // output "Ignored: {{1 + 2}}"
  8782. * ```
  8783. */
  8784. class NgNonBindable {
  8785. }
  8786. /**
  8787. * Adds or removes styles based on an {expression}.
  8788. *
  8789. * When the expression assigned to `ng-style` evaluates to an object, the corresponding element
  8790. * styles are updated. Style names to update are taken from the object keys and values - from the
  8791. * corresponding object values.
  8792. *
  8793. * # Example:
  8794. *
  8795. * ```
  8796. * <div [ng-style]="{'text-align': alignExp}"></div>
  8797. * ```
  8798. *
  8799. * In the above example the `text-align` style will be updated based on the `alignExp` value
  8800. * changes.
  8801. *
  8802. * # Syntax
  8803. *
  8804. * - `<div [ng-style]="{'text-align': alignExp}"></div>`
  8805. * - `<div [ng-style]="styleExp"></div>`
  8806. */
  8807. class NgStyle {
  8808. rawStyle: any;
  8809. doCheck(): void;
  8810. }
  8811. class SwitchView {
  8812. create(): void;
  8813. destroy(): void;
  8814. }
  8815. /**
  8816. * The `NgSwitch` directive is used to conditionally swap DOM structure on your template based on a
  8817. * scope expression.
  8818. * Elements within `NgSwitch` but without `NgSwitchWhen` or `NgSwitchDefault` directives will be
  8819. * preserved at the location as specified in the template.
  8820. *
  8821. * `NgSwitch` simply chooses nested elements and makes them visible based on which element matches
  8822. * the value obtained from the evaluated expression. In other words, you define a container element
  8823. * (where you place the directive), place an expression on the **`[ng-switch]="..."` attribute**),
  8824. * define any inner elements inside of the directive and place a `[ng-switch-when]` attribute per
  8825. * element.
  8826. * The when attribute is used to inform NgSwitch which element to display when the expression is
  8827. * evaluated. If a matching expression is not found via a when attribute then an element with the
  8828. * default attribute is displayed.
  8829. *
  8830. * # Example:
  8831. *
  8832. * ```
  8833. * <ANY [ng-switch]="expression">
  8834. * <template [ng-switch-when]="whenExpression1">...</template>
  8835. * <template [ng-switch-when]="whenExpression1">...</template>
  8836. * <template ng-switch-default>...</template>
  8837. * </ANY>
  8838. * ```
  8839. */
  8840. class NgSwitch {
  8841. ngSwitch: any;
  8842. }
  8843. /**
  8844. * Defines a case statement as an expression.
  8845. *
  8846. * If multiple `NgSwitchWhen` match the `NgSwitch` value, all of them are displayed.
  8847. *
  8848. * Example:
  8849. *
  8850. * ```
  8851. * // match against a context variable
  8852. * <template [ng-switch-when]="contextVariable">...</template>
  8853. *
  8854. * // match against a constant string
  8855. * <template ng-switch-when="stringValue">...</template>
  8856. * ```
  8857. */
  8858. class NgSwitchWhen {
  8859. ngSwitchWhen: any;
  8860. }
  8861. /**
  8862. * Defines a default case statement.
  8863. *
  8864. * Default case statements are displayed when no `NgSwitchWhen` match the `ng-switch` value.
  8865. *
  8866. * Example:
  8867. *
  8868. * ```
  8869. * <template ng-switch-default>...</template>
  8870. * ```
  8871. */
  8872. class NgSwitchDefault {
  8873. }
  8874. /**
  8875. * Omitting from external API doc as this is really an abstract internal concept.
  8876. */
  8877. class AbstractControl {
  8878. validator: Function;
  8879. value: any;
  8880. status: string;
  8881. valid: boolean;
  8882. errors: StringMap<string, any>;
  8883. pristine: boolean;
  8884. dirty: boolean;
  8885. touched: boolean;
  8886. untouched: boolean;
  8887. valueChanges: Observable;
  8888. markAsTouched(): void;
  8889. markAsDirty({onlySelf}?: {onlySelf?: boolean}): void;
  8890. setParent(parent: ControlGroup | ControlArray): void;
  8891. updateValidity({onlySelf}?: {onlySelf?: boolean}): void;
  8892. updateValueAndValidity({onlySelf, emitEvent}?: {onlySelf?: boolean, emitEvent?: boolean}): void;
  8893. find(path: Array<string | number>| string): AbstractControl;
  8894. getError(errorCode: string, path?: string[]): any;
  8895. hasError(errorCode: string, path?: string[]): boolean;
  8896. }
  8897. /**
  8898. * Defines a part of a form that cannot be divided into other controls.
  8899. *
  8900. * `Control` is one of the three fundamental building blocks used to define forms in Angular, along
  8901. * with
  8902. * {@link ControlGroup} and {@link ControlArray}.
  8903. */
  8904. class Control extends AbstractControl {
  8905. updateValue(value: any, {onlySelf, emitEvent, emitModelToViewChange}?:
  8906. {onlySelf?: boolean, emitEvent?: boolean, emitModelToViewChange?: boolean}): void;
  8907. registerOnChange(fn: Function): void;
  8908. }
  8909. /**
  8910. * Defines a part of a form, of fixed length, that can contain other controls.
  8911. *
  8912. * A ControlGroup aggregates the values and errors of each {@link Control} in the group. Thus, if
  8913. * one of the controls
  8914. * in a group is invalid, the entire group is invalid. Similarly, if a control changes its value,
  8915. * the entire group
  8916. * changes as well.
  8917. *
  8918. * `ControlGroup` is one of the three fundamental building blocks used to define forms in Angular,
  8919. * along with
  8920. * {@link Control} and {@link ControlArray}. {@link ControlArray} can also contain other controls,
  8921. * but is of variable
  8922. * length.
  8923. */
  8924. class ControlGroup extends AbstractControl {
  8925. controls: StringMap<string, AbstractControl>;
  8926. addControl(name: string, c: AbstractControl): void;
  8927. removeControl(name: string): void;
  8928. include(controlName: string): void;
  8929. exclude(controlName: string): void;
  8930. contains(controlName: string): boolean;
  8931. }
  8932. /**
  8933. * Defines a part of a form, of variable length, that can contain other controls.
  8934. *
  8935. * A `ControlArray` aggregates the values and errors of each {@link Control} in the group. Thus, if
  8936. * one of the controls
  8937. * in a group is invalid, the entire group is invalid. Similarly, if a control changes its value,
  8938. * the entire group
  8939. * changes as well.
  8940. *
  8941. * `ControlArray` is one of the three fundamental building blocks used to define forms in Angular,
  8942. * along with {@link Control} and {@link ControlGroup}. {@link ControlGroup} can also contain
  8943. * other controls, but is of fixed length.
  8944. */
  8945. class ControlArray extends AbstractControl {
  8946. controls: AbstractControl[];
  8947. at(index: number): AbstractControl;
  8948. push(control: AbstractControl): void;
  8949. insert(index: number, control: AbstractControl): void;
  8950. removeAt(index: number): void;
  8951. length: number;
  8952. }
  8953. class AbstractControlDirective {
  8954. control: AbstractControl;
  8955. value: any;
  8956. valid: boolean;
  8957. errors: StringMap<string, any>;
  8958. pristine: boolean;
  8959. dirty: boolean;
  8960. touched: boolean;
  8961. untouched: boolean;
  8962. }
  8963. /**
  8964. * An interface that {@link NgFormModel} and {@link NgForm} implement.
  8965. *
  8966. * Only used by the forms module.
  8967. */
  8968. interface Form {
  8969. addControl(dir: NgControl): void;
  8970. removeControl(dir: NgControl): void;
  8971. getControl(dir: NgControl): Control;
  8972. addControlGroup(dir: NgControlGroup): void;
  8973. removeControlGroup(dir: NgControlGroup): void;
  8974. getControlGroup(dir: NgControlGroup): ControlGroup;
  8975. updateModel(dir: NgControl, value: any): void;
  8976. }
  8977. /**
  8978. * A directive that contains a group of [NgControl].
  8979. *
  8980. * Only used by the forms module.
  8981. */
  8982. class ControlContainer extends AbstractControlDirective {
  8983. name: string;
  8984. formDirective: Form;
  8985. path: string[];
  8986. }
  8987. /**
  8988. * Creates and binds a control with a specified name to a DOM element.
  8989. *
  8990. * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}.
  8991. *
  8992. * # Example
  8993. *
  8994. * In this example, we create the login and password controls.
  8995. * We can work with each control separately: check its validity, get its value, listen to its
  8996. * changes.
  8997. *
  8998. * ```
  8999. * @Component({selector: "login-comp"})
  9000. * @View({
  9001. * directives: [FORM_DIRECTIVES],
  9002. * template: `
  9003. * <form #f="form" (submit)='onLogIn(f.value)'>
  9004. * Login <input type='text' ng-control='login' #l="form">
  9005. * <div *ng-if="!l.valid">Login is invalid</div>
  9006. *
  9007. * Password <input type='password' ng-control='password'>
  9008. *
  9009. * <button type='submit'>Log in!</button>
  9010. * </form>
  9011. * `})
  9012. * class LoginComp {
  9013. * onLogIn(value) {
  9014. * // value === {login: 'some login', password: 'some password'}
  9015. * }
  9016. * }
  9017. * ```
  9018. *
  9019. * We can also use ng-model to bind a domain model to the form.
  9020. *
  9021. * ```
  9022. * @Component({selector: "login-comp"})
  9023. * @View({
  9024. * directives: [FORM_DIRECTIVES],
  9025. * template: `
  9026. * <form (submit)='onLogIn()'>
  9027. * Login <input type='text' ng-control='login' [(ng-model)]="credentials.login">
  9028. * Password <input type='password' ng-control='password'
  9029. * [(ng-model)]="credentials.password">
  9030. * <button type='submit'>Log in!</button>
  9031. * </form>
  9032. * `})
  9033. * class LoginComp {
  9034. * credentials: {login:string, password:string};
  9035. *
  9036. * onLogIn() {
  9037. * // this.credentials.login === "some login"
  9038. * // this.credentials.password === "some password"
  9039. * }
  9040. * }
  9041. * ```
  9042. */
  9043. class NgControlName extends NgControl {
  9044. update: any;
  9045. model: any;
  9046. viewModel: any;
  9047. ngValidators: QueryList<NgValidator>;
  9048. onChanges(c: StringMap<string, any>): void;
  9049. onDestroy(): void;
  9050. viewToModelUpdate(newValue: any): void;
  9051. path: string[];
  9052. formDirective: any;
  9053. control: Control;
  9054. validator: Function;
  9055. }
  9056. /**
  9057. * Binds an existing control to a DOM element.
  9058. *
  9059. * # Example
  9060. *
  9061. * In this example, we bind the control to an input element. When the value of the input element
  9062. * changes, the value of
  9063. * the control will reflect that change. Likewise, if the value of the control changes, the input
  9064. * element reflects that
  9065. * change.
  9066. *
  9067. * ```
  9068. * @Component({selector: "login-comp"})
  9069. * @View({
  9070. * directives: [FORM_DIRECTIVES],
  9071. * template: "<input type='text' [ng-form-control]='loginControl'>"
  9072. * })
  9073. * class LoginComp {
  9074. * loginControl:Control;
  9075. *
  9076. * constructor() {
  9077. * this.loginControl = new Control('');
  9078. * }
  9079. * }
  9080. *
  9081. * ```
  9082. *
  9083. * We can also use ng-model to bind a domain model to the form.
  9084. *
  9085. * ```
  9086. * @Component({selector: "login-comp"})
  9087. * @View({
  9088. * directives: [FORM_DIRECTIVES],
  9089. * template: "<input type='text' [ng-form-control]='loginControl' [(ng-model)]='login'>"
  9090. * })
  9091. * class LoginComp {
  9092. * loginControl:Control;
  9093. * login:string;
  9094. *
  9095. * constructor() {
  9096. * this.loginControl = new Control('');
  9097. * }
  9098. * }
  9099. * ```
  9100. */
  9101. class NgFormControl extends NgControl {
  9102. form: Control;
  9103. update: any;
  9104. model: any;
  9105. viewModel: any;
  9106. ngValidators: QueryList<NgValidator>;
  9107. onChanges(c: StringMap<string, any>): void;
  9108. path: string[];
  9109. control: Control;
  9110. validator: Function;
  9111. viewToModelUpdate(newValue: any): void;
  9112. }
  9113. /**
  9114. * Binds a domain model to the form.
  9115. *
  9116. * # Example
  9117. * ```
  9118. * @Component({selector: "search-comp"})
  9119. * @View({
  9120. * directives: [FORM_DIRECTIVES],
  9121. * template: `
  9122. * <input type='text' [(ng-model)]="searchQuery">
  9123. * `})
  9124. * class SearchComp {
  9125. * searchQuery: string;
  9126. * }
  9127. * ```
  9128. */
  9129. class NgModel extends NgControl {
  9130. update: any;
  9131. model: any;
  9132. viewModel: any;
  9133. ngValidators: QueryList<NgValidator>;
  9134. onChanges(c: StringMap<string, any>): void;
  9135. control: Control;
  9136. path: string[];
  9137. validator: Function;
  9138. viewToModelUpdate(newValue: any): void;
  9139. }
  9140. /**
  9141. * An abstract class that all control directive extend.
  9142. *
  9143. * It binds a {@link Control} object to a DOM element.
  9144. */
  9145. class NgControl extends AbstractControlDirective {
  9146. name: string;
  9147. valueAccessor: ControlValueAccessor;
  9148. validator: Function;
  9149. path: string[];
  9150. viewToModelUpdate(newValue: any): void;
  9151. }
  9152. /**
  9153. * Creates and binds a control group to a DOM element.
  9154. *
  9155. * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}.
  9156. *
  9157. * # Example
  9158. *
  9159. * In this example, we create the credentials and personal control groups.
  9160. * We can work with each group separately: check its validity, get its value, listen to its changes.
  9161. *
  9162. * ```
  9163. * @Component({selector: "signup-comp"})
  9164. * @View({
  9165. * directives: [FORM_DIRECTIVES],
  9166. * template: `
  9167. * <form #f="form" (submit)='onSignUp(f.value)'>
  9168. * <div ng-control-group='credentials' #credentials="form">
  9169. * Login <input type='text' ng-control='login'>
  9170. * Password <input type='password' ng-control='password'>
  9171. * </div>
  9172. * <div *ng-if="!credentials.valid">Credentials are invalid</div>
  9173. *
  9174. * <div ng-control-group='personal'>
  9175. * Name <input type='text' ng-control='name'>
  9176. * </div>
  9177. * <button type='submit'>Sign Up!</button>
  9178. * </form>
  9179. * `})
  9180. * class SignupComp {
  9181. * onSignUp(value) {
  9182. * // value === {personal: {name: 'some name'},
  9183. * // credentials: {login: 'some login', password: 'some password'}}
  9184. * }
  9185. * }
  9186. *
  9187. * ```
  9188. */
  9189. class NgControlGroup extends ControlContainer {
  9190. onInit(): void;
  9191. onDestroy(): void;
  9192. control: ControlGroup;
  9193. path: string[];
  9194. formDirective: Form;
  9195. }
  9196. /**
  9197. * Binds an existing control group to a DOM element.
  9198. *
  9199. * # Example
  9200. *
  9201. * In this example, we bind the control group to the form element, and we bind the login and
  9202. * password controls to the
  9203. * login and password elements.
  9204. *
  9205. * ```
  9206. * @Component({selector: "login-comp"})
  9207. * @View({
  9208. * directives: [FORM_DIRECTIVES],
  9209. * template: "<form [ng-form-model]='loginForm'>" +
  9210. * "Login <input type='text' ng-control='login'>" +
  9211. * "Password <input type='password' ng-control='password'>" +
  9212. * "<button (click)="onLogin()">Login</button>" +
  9213. * "</form>"
  9214. * })
  9215. * class LoginComp {
  9216. * loginForm:ControlGroup;
  9217. *
  9218. * constructor() {
  9219. * this.loginForm = new ControlGroup({
  9220. * login: new Control(""),
  9221. * password: new Control("")
  9222. * });
  9223. * }
  9224. *
  9225. * onLogin() {
  9226. * // this.loginForm.value
  9227. * }
  9228. * }
  9229. *
  9230. * ```
  9231. *
  9232. * We can also use ng-model to bind a domain model to the form.
  9233. *
  9234. * ```
  9235. * @Component({selector: "login-comp"})
  9236. * @View({
  9237. * directives: [FORM_DIRECTIVES],
  9238. * template: "<form [ng-form-model]='loginForm'>" +
  9239. * "Login <input type='text' ng-control='login' [(ng-model)]='login'>" +
  9240. * "Password <input type='password' ng-control='password' [(ng-model)]='password'>" +
  9241. * "<button (click)="onLogin()">Login</button>" +
  9242. * "</form>"
  9243. * })
  9244. * class LoginComp {
  9245. * credentials:{login:string, password:string}
  9246. * loginForm:ControlGroup;
  9247. *
  9248. * constructor() {
  9249. * this.loginForm = new ControlGroup({
  9250. * login: new Control(""),
  9251. * password: new Control("")
  9252. * });
  9253. * }
  9254. *
  9255. * onLogin() {
  9256. * // this.credentials.login === 'some login'
  9257. * // this.credentials.password === 'some password'
  9258. * }
  9259. * }
  9260. * ```
  9261. */
  9262. class NgFormModel extends ControlContainer implements Form {
  9263. form: ControlGroup;
  9264. directives: NgControl[];
  9265. ngSubmit: any;
  9266. onChanges(_: any): void;
  9267. formDirective: Form;
  9268. control: ControlGroup;
  9269. path: string[];
  9270. addControl(dir: NgControl): void;
  9271. getControl(dir: NgControl): Control;
  9272. removeControl(dir: NgControl): void;
  9273. addControlGroup(dir: NgControlGroup): void;
  9274. removeControlGroup(dir: NgControlGroup): void;
  9275. getControlGroup(dir: NgControlGroup): ControlGroup;
  9276. updateModel(dir: NgControl, value: any): void;
  9277. onSubmit(): boolean;
  9278. }
  9279. /**
  9280. * Creates and binds a form object to a DOM element.
  9281. *
  9282. * # Example
  9283. *
  9284. * ```
  9285. * @Component({selector: "signup-comp"})
  9286. * @View({
  9287. * directives: [FORM_DIRECTIVES],
  9288. * template: `
  9289. * <form #f="form" (submit)='onSignUp(f.value)'>
  9290. * <div ng-control-group='credentials' #credentials="form">
  9291. * Login <input type='text' ng-control='login'>
  9292. * Password <input type='password' ng-control='password'>
  9293. * </div>
  9294. * <div *ng-if="!credentials.valid">Credentials are invalid</div>
  9295. *
  9296. * <div ng-control-group='personal'>
  9297. * Name <input type='text' ng-control='name'>
  9298. * </div>
  9299. * <button type='submit'>Sign Up!</button>
  9300. * </form>
  9301. * `})
  9302. * class SignupComp {
  9303. * onSignUp(value) {
  9304. * // value === {personal: {name: 'some name'},
  9305. * // credentials: {login: 'some login', password: 'some password'}}
  9306. * }
  9307. * }
  9308. *
  9309. * ```
  9310. */
  9311. class NgForm extends ControlContainer implements Form {
  9312. form: ControlGroup;
  9313. ngSubmit: any;
  9314. formDirective: Form;
  9315. control: ControlGroup;
  9316. path: string[];
  9317. controls: StringMap<string, AbstractControl>;
  9318. addControl(dir: NgControl): void;
  9319. getControl(dir: NgControl): Control;
  9320. removeControl(dir: NgControl): void;
  9321. addControlGroup(dir: NgControlGroup): void;
  9322. removeControlGroup(dir: NgControlGroup): void;
  9323. getControlGroup(dir: NgControlGroup): ControlGroup;
  9324. updateModel(dir: NgControl, value: any): void;
  9325. onSubmit(): boolean;
  9326. }
  9327. /**
  9328. * A bridge between a control and a native element.
  9329. *
  9330. * Please see {@link DefaultValueAccessor} for more information.
  9331. */
  9332. interface ControlValueAccessor {
  9333. writeValue(obj: any): void;
  9334. registerOnChange(fn: any): void;
  9335. registerOnTouched(fn: any): void;
  9336. }
  9337. /**
  9338. * The default accessor for writing a value and listening to changes that is used by the
  9339. * {@link NgModel}, {@link NgFormControl}, and {@link NgControlName} directives.
  9340. *
  9341. * # Example
  9342. * ```
  9343. * <input type="text" [(ng-model)]="searchQuery">
  9344. * ```
  9345. */
  9346. class DefaultValueAccessor implements ControlValueAccessor {
  9347. cd: NgControl;
  9348. onChange: any;
  9349. onTouched: any;
  9350. renderer: Renderer;
  9351. elementRef: ElementRef;
  9352. writeValue(value: any): void;
  9353. ngClassUntouched: boolean;
  9354. ngClassTouched: boolean;
  9355. ngClassPristine: boolean;
  9356. ngClassDirty: boolean;
  9357. ngClassValid: boolean;
  9358. ngClassInvalid: boolean;
  9359. registerOnChange(fn: (_: any) => void): void;
  9360. registerOnTouched(fn: () => void): void;
  9361. }
  9362. /**
  9363. * The accessor for writing a value and listening to changes on a checkbox input element.
  9364. *
  9365. * # Example
  9366. * ```
  9367. * <input type="checkbox" [ng-control]="rememberLogin">
  9368. * ```
  9369. */
  9370. class CheckboxControlValueAccessor implements ControlValueAccessor {
  9371. cd: NgControl;
  9372. onChange: any;
  9373. onTouched: any;
  9374. renderer: Renderer;
  9375. elementRef: ElementRef;
  9376. writeValue(value: any): void;
  9377. ngClassUntouched: boolean;
  9378. ngClassTouched: boolean;
  9379. ngClassPristine: boolean;
  9380. ngClassDirty: boolean;
  9381. ngClassValid: boolean;
  9382. ngClassInvalid: boolean;
  9383. registerOnChange(fn: (_: any) => {}): void;
  9384. registerOnTouched(fn: () => {}): void;
  9385. }
  9386. /**
  9387. * Marks <option> as dynamic, so Angular can be notified when options change.
  9388. *
  9389. * #Example:
  9390. *
  9391. * ```
  9392. * <select ng-control="city">
  9393. * <option *ng-for="#c of cities" [value]="c"></option>
  9394. * </select>
  9395. * ```
  9396. */
  9397. class NgSelectOption {
  9398. }
  9399. /**
  9400. * The accessor for writing a value and listening to changes on a select element.
  9401. */
  9402. class SelectControlValueAccessor implements ControlValueAccessor {
  9403. cd: NgControl;
  9404. value: string;
  9405. onChange: any;
  9406. onTouched: any;
  9407. renderer: Renderer;
  9408. elementRef: ElementRef;
  9409. writeValue(value: any): void;
  9410. ngClassUntouched: boolean;
  9411. ngClassTouched: boolean;
  9412. ngClassPristine: boolean;
  9413. ngClassDirty: boolean;
  9414. ngClassValid: boolean;
  9415. ngClassInvalid: boolean;
  9416. registerOnChange(fn: () => any): void;
  9417. registerOnTouched(fn: () => any): void;
  9418. }
  9419. /**
  9420. * A list of all the form directives used as part of a `@View` annotation.
  9421. *
  9422. * This is a shorthand for importing them each individually.
  9423. */
  9424. const FORM_DIRECTIVES : Type[] ;
  9425. /**
  9426. * Provides a set of validators used by form controls.
  9427. *
  9428. * # Example
  9429. *
  9430. * ```
  9431. * var loginControl = new Control("", Validators.required)
  9432. * ```
  9433. */
  9434. class Validators {
  9435. static required(c:Control): StringMap<string, boolean>;
  9436. static nullValidator(c: any): StringMap<string, boolean>;
  9437. static compose(validators: Function[]): Function;
  9438. static group(c:ControlGroup): StringMap<string, boolean>;
  9439. static array(c:ControlArray): StringMap<string, boolean>;
  9440. }
  9441. class NgValidator {
  9442. validator: Function;
  9443. }
  9444. class NgRequiredValidator extends NgValidator {
  9445. validator: Function;
  9446. }
  9447. /**
  9448. * Creates a form object from a user-specified configuration.
  9449. *
  9450. * # Example
  9451. *
  9452. * ```
  9453. * import {Component, View, bootstrap} from 'angular2/angular2';
  9454. * import {FormBuilder, Validators, FORM_DIRECTIVES, ControlGroup} from 'angular2/forms';
  9455. *
  9456. * @Component({
  9457. * selector: 'login-comp',
  9458. * viewBindings: [
  9459. * FormBuilder
  9460. * ]
  9461. * })
  9462. * @View({
  9463. * template: `
  9464. * <form [control-group]="loginForm">
  9465. * Login <input control="login">
  9466. *
  9467. * <div control-group="passwordRetry">
  9468. * Password <input type="password" control="password">
  9469. * Confirm password <input type="password" control="passwordConfirmation">
  9470. * </div>
  9471. * </form>
  9472. * `,
  9473. * directives: [
  9474. * FORM_DIRECTIVES
  9475. * ]
  9476. * })
  9477. * class LoginComp {
  9478. * loginForm: ControlGroup;
  9479. *
  9480. * constructor(builder: FormBuilder) {
  9481. * this.loginForm = builder.group({
  9482. * login: ["", Validators.required],
  9483. *
  9484. * passwordRetry: builder.group({
  9485. * password: ["", Validators.required],
  9486. * passwordConfirmation: ["", Validators.required]
  9487. * })
  9488. * });
  9489. * }
  9490. * }
  9491. *
  9492. * bootstrap(LoginComp)
  9493. * ```
  9494. *
  9495. * This example creates a {@link ControlGroup} that consists of a `login` {@link Control}, and a
  9496. * nested
  9497. * {@link ControlGroup} that defines a `password` and a `passwordConfirmation` {@link Control}:
  9498. *
  9499. * ```
  9500. * var loginForm = builder.group({
  9501. * login: ["", Validators.required],
  9502. *
  9503. * passwordRetry: builder.group({
  9504. * password: ["", Validators.required],
  9505. * passwordConfirmation: ["", Validators.required]
  9506. * })
  9507. * });
  9508. *
  9509. * ```
  9510. */
  9511. class FormBuilder {
  9512. group(controlsConfig: StringMap<string, any>, extra?: StringMap<string, any>): ControlGroup;
  9513. control(value: Object, validator?: Function): Control;
  9514. array(controlsConfig: any[], validator?: Function): ControlArray;
  9515. }
  9516. const FORM_BINDINGS : Type[] ;
  9517. class RenderDirectiveMetadata {
  9518. static DIRECTIVE_TYPE: any;
  9519. static COMPONENT_TYPE: any;
  9520. static create({id, selector, compileChildren, events, host, properties, readAttributes, type,
  9521. callOnDestroy, callOnChanges, callDoCheck, callOnInit, callAfterContentInit,
  9522. callAfterContentChecked, callAfterViewInit, callAfterViewChecked, changeDetection,
  9523. exportAs}: {
  9524. id?: string,
  9525. selector?: string,
  9526. compileChildren?: boolean,
  9527. events?: string[],
  9528. host?: Map<string, string>,
  9529. properties?: string[],
  9530. readAttributes?: string[],
  9531. type?: number,
  9532. callOnDestroy?: boolean,
  9533. callOnChanges?: boolean,
  9534. callDoCheck?: boolean,
  9535. callOnInit?: boolean,
  9536. callAfterContentInit?: boolean,
  9537. callAfterContentChecked?: boolean,
  9538. callAfterViewInit?: boolean,
  9539. callAfterViewChecked?: boolean,
  9540. changeDetection?: ChangeDetectionStrategy,
  9541. exportAs?: string
  9542. }): RenderDirectiveMetadata;
  9543. id: any;
  9544. selector: string;
  9545. compileChildren: boolean;
  9546. events: string[];
  9547. properties: string[];
  9548. readAttributes: string[];
  9549. type: number;
  9550. callOnDestroy: boolean;
  9551. callOnChanges: boolean;
  9552. callDoCheck: boolean;
  9553. callOnInit: boolean;
  9554. callAfterContentInit: boolean;
  9555. callAfterContentChecked: boolean;
  9556. callAfterViewInit: boolean;
  9557. callAfterViewChecked: boolean;
  9558. changeDetection: ChangeDetectionStrategy;
  9559. exportAs: string;
  9560. hostListeners: Map<string, string>;
  9561. hostProperties: Map<string, string>;
  9562. hostAttributes: Map<string, string>;
  9563. }
  9564. class DomRenderer extends Renderer {
  9565. createRootHostView(hostProtoViewRef: RenderProtoViewRef, fragmentCount: number, hostElementSelector: string): RenderViewWithFragments;
  9566. createView(protoViewRef: RenderProtoViewRef, fragmentCount: number): RenderViewWithFragments;
  9567. destroyView(viewRef: RenderViewRef): void;
  9568. getNativeElementSync(location: RenderElementRef): any;
  9569. getRootNodes(fragment: RenderFragmentRef): Node[];
  9570. attachFragmentAfterFragment(previousFragmentRef: RenderFragmentRef, fragmentRef: RenderFragmentRef): void;
  9571. attachFragmentAfterElement(elementRef: RenderElementRef, fragmentRef: RenderFragmentRef): void;
  9572. detachFragment(fragmentRef: RenderFragmentRef): void;
  9573. hydrateView(viewRef: RenderViewRef): void;
  9574. dehydrateView(viewRef: RenderViewRef): void;
  9575. setElementProperty(location: RenderElementRef, propertyName: string, propertyValue: any): void;
  9576. setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string): void;
  9577. setElementClass(location: RenderElementRef, className: string, isAdd: boolean): void;
  9578. setElementStyle(location: RenderElementRef, styleName: string, styleValue: string): void;
  9579. invokeElementMethod(location: RenderElementRef, methodName: string, args: any[]): void;
  9580. setText(viewRef: RenderViewRef, textNodeIndex: number, text: string): void;
  9581. setEventDispatcher(viewRef: RenderViewRef, dispatcher: any): void;
  9582. }
  9583. /**
  9584. * A dispatcher for all events happening in a view.
  9585. */
  9586. interface RenderEventDispatcher {
  9587. /**
  9588. * Called when an event was triggered for a on-* attribute on an element.
  9589. * @param {Map<string, any>} locals Locals to be used to evaluate the
  9590. * event expressions
  9591. * @return {boolean} False if `preventDefault` should be called on the DOM event.
  9592. */
  9593. dispatchRenderEvent(elementIndex: number, eventName: string, locals: Map<string, any>): boolean;
  9594. }
  9595. class Renderer {
  9596. /**
  9597. * Creates a root host view that includes the given element.
  9598. * Note that the fragmentCount needs to be passed in so that we can create a result
  9599. * synchronously even when dealing with webworkers!
  9600. *
  9601. * @param {RenderProtoViewRef} hostProtoViewRef a RenderProtoViewRef of type
  9602. * ProtoViewDto.HOST_VIEW_TYPE
  9603. * @param {any} hostElementSelector css selector for the host element (will be queried against the
  9604. * main document)
  9605. * @return {RenderViewWithFragments} the created view including fragments
  9606. */
  9607. createRootHostView(hostProtoViewRef: RenderProtoViewRef, fragmentCount: number, hostElementSelector: string): RenderViewWithFragments;
  9608. /**
  9609. * Creates a regular view out of the given ProtoView.
  9610. * Note that the fragmentCount needs to be passed in so that we can create a result
  9611. * synchronously even when dealing with webworkers!
  9612. */
  9613. createView(protoViewRef: RenderProtoViewRef, fragmentCount: number): RenderViewWithFragments;
  9614. /**
  9615. * Destroys the given view after it has been dehydrated and detached
  9616. */
  9617. destroyView(viewRef: RenderViewRef): void;
  9618. /**
  9619. * Attaches a fragment after another fragment.
  9620. */
  9621. attachFragmentAfterFragment(previousFragmentRef: RenderFragmentRef, fragmentRef: RenderFragmentRef): void;
  9622. /**
  9623. * Attaches a fragment after an element.
  9624. */
  9625. attachFragmentAfterElement(elementRef: RenderElementRef, fragmentRef: RenderFragmentRef): void;
  9626. /**
  9627. * Detaches a fragment.
  9628. */
  9629. detachFragment(fragmentRef: RenderFragmentRef): void;
  9630. /**
  9631. * Hydrates a view after it has been attached. Hydration/dehydration is used for reusing views
  9632. * inside of the view pool.
  9633. */
  9634. hydrateView(viewRef: RenderViewRef): void;
  9635. /**
  9636. * Dehydrates a view after it has been attached. Hydration/dehydration is used for reusing views
  9637. * inside of the view pool.
  9638. */
  9639. dehydrateView(viewRef: RenderViewRef): void;
  9640. /**
  9641. * Returns the native element at the given location.
  9642. * Attention: In a WebWorker scenario, this should always return null!
  9643. */
  9644. getNativeElementSync(location: RenderElementRef): any;
  9645. /**
  9646. * Sets a property on an element.
  9647. */
  9648. setElementProperty(location: RenderElementRef, propertyName: string, propertyValue: any): void;
  9649. /**
  9650. * Sets an attribute on an element.
  9651. */
  9652. setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string): void;
  9653. /**
  9654. * Sets a class on an element.
  9655. */
  9656. setElementClass(location: RenderElementRef, className: string, isAdd: boolean): void;
  9657. /**
  9658. * Sets a style on an element.
  9659. */
  9660. setElementStyle(location: RenderElementRef, styleName: string, styleValue: string): void;
  9661. /**
  9662. * Calls a method on an element.
  9663. */
  9664. invokeElementMethod(location: RenderElementRef, methodName: string, args: any[]): void;
  9665. /**
  9666. * Sets the value of a text node.
  9667. */
  9668. setText(viewRef: RenderViewRef, textNodeIndex: number, text: string): void;
  9669. /**
  9670. * Sets the dispatcher for all events of the given view
  9671. */
  9672. setEventDispatcher(viewRef: RenderViewRef, dispatcher: RenderEventDispatcher): void;
  9673. }
  9674. /**
  9675. * Abstract reference to the element which can be marshaled across web-worker boundary.
  9676. *
  9677. * This interface is used by the Renderer API.
  9678. */
  9679. interface RenderElementRef {
  9680. /**
  9681. * Reference to the `RenderViewRef` where the `RenderElementRef` is inside of.
  9682. */
  9683. renderView: RenderViewRef;
  9684. /**
  9685. * Index of the element inside the `RenderViewRef`.
  9686. *
  9687. * This is used internally by the Angular framework to locate elements.
  9688. */
  9689. renderBoundElementIndex: number;
  9690. }
  9691. class RenderViewRef {
  9692. }
  9693. class RenderProtoViewRef {
  9694. }
  9695. class RenderFragmentRef {
  9696. }
  9697. class RenderViewWithFragments {
  9698. viewRef: RenderViewRef;
  9699. fragmentRefs: RenderFragmentRef[];
  9700. }
  9701. class ViewDefinition {
  9702. componentId: string;
  9703. templateAbsUrl: string;
  9704. template: string;
  9705. directives: RenderDirectiveMetadata[];
  9706. styleAbsUrls: string[];
  9707. styles: string[];
  9708. encapsulation: ViewEncapsulation;
  9709. }
  9710. const DOCUMENT : OpaqueToken ;
  9711. /**
  9712. * A unique id (string) for an angular application.
  9713. */
  9714. const APP_ID : OpaqueToken ;
  9715. /**
  9716. * Defines when a compiled template should be stored as a string
  9717. * rather than keeping its Nodes to preserve memory.
  9718. */
  9719. const MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE : OpaqueToken ;
  9720. /**
  9721. * Create trace scope.
  9722. *
  9723. * Scopes must be strictly nested and are analogous to stack frames, but
  9724. * do not have to follow the stack frames. Instead it is recommended that they follow logical
  9725. * nesting. You may want to use
  9726. * [Event
  9727. * Signatures](http://google.github.io/tracing-framework/instrumenting-code.html#custom-events)
  9728. * as they are defined in WTF.
  9729. *
  9730. * Used to mark scope entry. The return value is used to leave the scope.
  9731. *
  9732. * var myScope = wtfCreateScope('MyClass#myMethod(ascii someVal)');
  9733. *
  9734. * someMethod() {
  9735. * var s = myScope('Foo'); // 'Foo' gets stored in tracing UI
  9736. * // DO SOME WORK HERE
  9737. * return wtfLeave(s, 123); // Return value 123
  9738. * }
  9739. *
  9740. * Note, adding try-finally block around the work to ensure that `wtfLeave` gets called can
  9741. * negatively impact the performance of your application. For this reason we recommend that
  9742. * you don't add them to ensure that `wtfLeave` gets called. In production `wtfLeave` is a noop and
  9743. * so try-finally block has no value. When debugging perf issues, skipping `wtfLeave`, do to
  9744. * exception, will produce incorrect trace, but presence of exception signifies logic error which
  9745. * needs to be fixed before the app should be profiled. Add try-finally only when you expect that
  9746. * an exception is expected during normal execution while profiling.
  9747. */
  9748. var wtfCreateScope : WtfScopeFn ;
  9749. /**
  9750. * Used to mark end of Scope.
  9751. *
  9752. * - `scope` to end.
  9753. * - `returnValue` (optional) to be passed to the WTF.
  9754. *
  9755. * Returns the `returnValue for easy chaining.
  9756. */
  9757. var wtfLeave : <T>(scope: any, returnValue?: T) => T ;
  9758. /**
  9759. * Used to mark Async start. Async are similar to scope but they don't have to be strictly nested.
  9760. * The return value is used in the call to [endAsync]. Async ranges only work if WTF has been
  9761. * enabled.
  9762. *
  9763. * someMethod() {
  9764. * var s = wtfStartTimeRange('HTTP:GET', 'some.url');
  9765. * var future = new Future.delay(5).then((_) {
  9766. * wtfEndTimeRange(s);
  9767. * });
  9768. * }
  9769. */
  9770. var wtfStartTimeRange : (rangeType: string, action: string) => any ;
  9771. /**
  9772. * Ends a async time range operation.
  9773. * [range] is the return value from [wtfStartTimeRange] Async ranges only work if WTF has been
  9774. * enabled.
  9775. */
  9776. var wtfEndTimeRange : (range: any) => void ;
  9777. interface WtfScopeFn {
  9778. (arg0?: any, arg1?: any): any;
  9779. }
  9780. /**
  9781. * Bootstrapping a Webworker Application
  9782. *
  9783. * You instantiate the application side by calling bootstrapWebworker from your webworker index
  9784. * script.
  9785. * You can call bootstrapWebworker() exactly as you would call bootstrap() in a regular Angular
  9786. * application
  9787. * See the bootstrap() docs for more details.
  9788. */
  9789. function bootstrapWebWorker(appComponentType: Type, componentInjectableBindings?: Array<Type | Binding | any[]>) : Promise<ApplicationRef> ;
  9790. /**
  9791. * Message Bus is a low level API used to communicate between the UI and the background.
  9792. * Communication is based on a channel abstraction. Messages published in a
  9793. * given channel to one MessageBusSink are received on the same channel
  9794. * by the corresponding MessageBusSource.
  9795. */
  9796. class MessageBus implements MessageBusSource, MessageBusSink {
  9797. /**
  9798. * Returns an {@link EventEmitter} that emits every time a messsage
  9799. * is received on the given channel.
  9800. */
  9801. from(channel: string): EventEmitter;
  9802. /**
  9803. * Returns an {@link EventEmitter} for the given channel
  9804. * To publish methods to that channel just call next (or add in dart) on the returned emitter
  9805. */
  9806. to(channel: string): EventEmitter;
  9807. }
  9808. interface MessageBusSource {
  9809. /**
  9810. * Returns an {@link EventEmitter} that emits every time a messsage
  9811. * is received on the given channel.
  9812. */
  9813. from(channel: string): EventEmitter;
  9814. }
  9815. interface MessageBusSink {
  9816. /**
  9817. * Returns an {@link EventEmitter} for the given channel
  9818. * To publish methods to that channel just call next (or add in dart) on the returned emitter
  9819. */
  9820. to(channel: string): EventEmitter;
  9821. }
  9822. class ClientMessageBrokerFactory {
  9823. createMessageBroker(channel: string): ClientMessageBroker;
  9824. }
  9825. class ClientMessageBroker {
  9826. channel: any;
  9827. runOnService(args: UiArguments, returnType: Type): Promise<any>;
  9828. }
  9829. class FnArg {
  9830. value: any;
  9831. type: Type;
  9832. }
  9833. class UiArguments {
  9834. method: string;
  9835. args: FnArg[];
  9836. }
  9837. class ServiceMessageBrokerFactory {
  9838. createMessageBroker(channel: string): ServiceMessageBroker;
  9839. }
  9840. /**
  9841. * Helper class for UIComponents that allows components to register methods.
  9842. * If a registered method message is received from the broker on the worker,
  9843. * the UIMessageBroker desererializes its arguments and calls the registered method.
  9844. * If that method returns a promise, the UIMessageBroker returns the result to the worker.
  9845. */
  9846. class ServiceMessageBroker {
  9847. channel: any;
  9848. registerMethod(methodName: string, signature: Type[], method: Function, returnType?: Type): void;
  9849. }
  9850. class ReceivedMessage {
  9851. method: string;
  9852. args: any[];
  9853. id: string;
  9854. type: string;
  9855. }
  9856. const PRIMITIVE : Type ;
  9857. class Serializer {
  9858. serialize(obj: any, type: Type): Object;
  9859. deserialize(map: any, type: Type, data?: any): any;
  9860. mapToObject(map: Map<string, any>, type?: Type): Object;
  9861. objectToMap(obj: StringMap<string, any>, type?: Type, data?: any): Map<string, any>;
  9862. allocateRenderViews(fragmentCount: number): void;
  9863. }
  9864. var ChangeDetectorRef: InjectableReference;
  9865. var ApplicationRef: InjectableReference;
  9866. var Compiler: InjectableReference;
  9867. var AppViewManager: InjectableReference;
  9868. var ViewRef: InjectableReference;
  9869. var ProtoViewRef: InjectableReference;
  9870. var ViewContainerRef: InjectableReference;
  9871. var ComponentRef: InjectableReference;
  9872. }
  9873. declare module "angular2/web_worker/worker" {
  9874. export = ngWorker;
  9875. }
  9876. declare module ngUi {
  9877. class WebWorkerApplication {
  9878. createClientMessageBroker(channel: string): ClientMessageBroker;
  9879. createServiceMessageBroker(channel: string): ServiceMessageBroker;
  9880. }
  9881. /**
  9882. * Bootstrapping a WebWorker
  9883. *
  9884. * You instantiate a WebWorker application by calling bootstrap with the URI of your worker's index
  9885. * script
  9886. * Note: The WebWorker script must call bootstrapWebworker once it is set up to complete the
  9887. * bootstrapping process
  9888. */
  9889. function bootstrap(uri: string) : WebWorkerInstance ;
  9890. function spawnWebWorker(uri: string) : WebWorkerInstance ;
  9891. /**
  9892. * Wrapper class that exposes the {@link WebWorkerApplication}
  9893. * Isolate instance and underyling {@link MessageBus} for lower level message passing.
  9894. */
  9895. class WebWorkerInstance {
  9896. app: WebWorkerApplication;
  9897. worker: Worker;
  9898. bus: MessageBus;
  9899. }
  9900. /**
  9901. * Use Rx.Observable but provides an adapter to make it work as specified here:
  9902. * https://github.com/jhusain/observable-spec
  9903. *
  9904. * Once a reference implementation of the spec is available, switch to it.
  9905. */
  9906. class EventEmitter extends Observable {
  9907. observer(generator: any): Rx.IDisposable;
  9908. toRx(): Rx.Observable<any>;
  9909. next(value: any): void;
  9910. throw(error: any): void;
  9911. return(value?: any): void;
  9912. }
  9913. class Observable {
  9914. observer(generator: any): Object;
  9915. }
  9916. /**
  9917. * Message Bus is a low level API used to communicate between the UI and the background.
  9918. * Communication is based on a channel abstraction. Messages published in a
  9919. * given channel to one MessageBusSink are received on the same channel
  9920. * by the corresponding MessageBusSource.
  9921. */
  9922. class MessageBus implements MessageBusSource, MessageBusSink {
  9923. /**
  9924. * Returns an {@link EventEmitter} that emits every time a messsage
  9925. * is received on the given channel.
  9926. */
  9927. from(channel: string): EventEmitter;
  9928. /**
  9929. * Returns an {@link EventEmitter} for the given channel
  9930. * To publish methods to that channel just call next (or add in dart) on the returned emitter
  9931. */
  9932. to(channel: string): EventEmitter;
  9933. }
  9934. interface MessageBusSource {
  9935. /**
  9936. * Returns an {@link EventEmitter} that emits every time a messsage
  9937. * is received on the given channel.
  9938. */
  9939. from(channel: string): EventEmitter;
  9940. }
  9941. interface MessageBusSink {
  9942. /**
  9943. * Returns an {@link EventEmitter} for the given channel
  9944. * To publish methods to that channel just call next (or add in dart) on the returned emitter
  9945. */
  9946. to(channel: string): EventEmitter;
  9947. }
  9948. /**
  9949. * Runtime representation of a type.
  9950. *
  9951. * In JavaScript a Type is a constructor function.
  9952. */
  9953. interface Type extends Function {
  9954. new(...args: any[]): any;
  9955. }
  9956. class ClientMessageBrokerFactory {
  9957. createMessageBroker(channel: string): ClientMessageBroker;
  9958. }
  9959. class ClientMessageBroker {
  9960. channel: any;
  9961. runOnService(args: UiArguments, returnType: Type): Promise<any>;
  9962. }
  9963. class FnArg {
  9964. value: any;
  9965. type: Type;
  9966. }
  9967. class UiArguments {
  9968. method: string;
  9969. args: FnArg[];
  9970. }
  9971. class ServiceMessageBrokerFactory {
  9972. createMessageBroker(channel: string): ServiceMessageBroker;
  9973. }
  9974. /**
  9975. * Helper class for UIComponents that allows components to register methods.
  9976. * If a registered method message is received from the broker on the worker,
  9977. * the UIMessageBroker desererializes its arguments and calls the registered method.
  9978. * If that method returns a promise, the UIMessageBroker returns the result to the worker.
  9979. */
  9980. class ServiceMessageBroker {
  9981. channel: any;
  9982. registerMethod(methodName: string, signature: Type[], method: Function, returnType?: Type): void;
  9983. }
  9984. class ReceivedMessage {
  9985. method: string;
  9986. args: any[];
  9987. id: string;
  9988. type: string;
  9989. }
  9990. const PRIMITIVE : Type ;
  9991. class Serializer {
  9992. serialize(obj: any, type: Type): Object;
  9993. deserialize(map: any, type: Type, data?: any): any;
  9994. mapToObject(map: Map<string, any>, type?: Type): Object;
  9995. objectToMap(obj: StringMap<string, any>, type?: Type, data?: any): Map<string, any>;
  9996. allocateRenderViews(fragmentCount: number): void;
  9997. }
  9998. }
  9999. declare module "angular2/web_worker/ui" {
  10000. export = ngUi;
  10001. }