angular2.d.ts 297 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213
  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. }