index.d.ts 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460
  1. /**
  2. * @license Angular v16.0.4
  3. * (c) 2010-2022 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { AfterViewInit } from '@angular/core';
  7. import { ChangeDetectorRef } from '@angular/core';
  8. import { ElementRef } from '@angular/core';
  9. import { EventEmitter } from '@angular/core';
  10. import * as i0 from '@angular/core';
  11. import { InjectionToken } from '@angular/core';
  12. import { Injector } from '@angular/core';
  13. import { ModuleWithProviders } from '@angular/core';
  14. import { Observable } from 'rxjs';
  15. import { OnChanges } from '@angular/core';
  16. import { OnDestroy } from '@angular/core';
  17. import { OnInit } from '@angular/core';
  18. import { Provider } from '@angular/core';
  19. import { Renderer2 } from '@angular/core';
  20. import { SimpleChanges } from '@angular/core';
  21. import { Type } from '@angular/core';
  22. import { Version } from '@angular/core';
  23. /**
  24. * This is the base class for `FormControl`, `FormGroup`, and `FormArray`.
  25. *
  26. * It provides some of the shared behavior that all controls and groups of controls have, like
  27. * running validators, calculating status, and resetting state. It also defines the properties
  28. * that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
  29. * instantiated directly.
  30. *
  31. * The first type parameter TValue represents the value type of the control (`control.value`).
  32. * The optional type parameter TRawValue represents the raw value type (`control.getRawValue()`).
  33. *
  34. * @see [Forms Guide](/guide/forms)
  35. * @see [Reactive Forms Guide](/guide/reactive-forms)
  36. * @see [Dynamic Forms Guide](/guide/dynamic-form)
  37. *
  38. * @publicApi
  39. */
  40. export declare abstract class AbstractControl<TValue = any, TRawValue extends TValue = TValue> {
  41. private _parent;
  42. private _asyncValidationSubscription;
  43. /**
  44. * The current value of the control.
  45. *
  46. * * For a `FormControl`, the current value.
  47. * * For an enabled `FormGroup`, the values of enabled controls as an object
  48. * with a key-value pair for each member of the group.
  49. * * For a disabled `FormGroup`, the values of all controls as an object
  50. * with a key-value pair for each member of the group.
  51. * * For a `FormArray`, the values of enabled controls as an array.
  52. *
  53. */
  54. readonly value: TValue;
  55. /**
  56. * Initialize the AbstractControl instance.
  57. *
  58. * @param validators The function or array of functions that is used to determine the validity of
  59. * this control synchronously.
  60. * @param asyncValidators The function or array of functions that is used to determine validity of
  61. * this control asynchronously.
  62. */
  63. constructor(validators: ValidatorFn | ValidatorFn[] | null, asyncValidators: AsyncValidatorFn | AsyncValidatorFn[] | null);
  64. /**
  65. * Returns the function that is used to determine the validity of this control synchronously.
  66. * If multiple validators have been added, this will be a single composed function.
  67. * See `Validators.compose()` for additional information.
  68. */
  69. get validator(): ValidatorFn | null;
  70. set validator(validatorFn: ValidatorFn | null);
  71. /**
  72. * Returns the function that is used to determine the validity of this control asynchronously.
  73. * If multiple validators have been added, this will be a single composed function.
  74. * See `Validators.compose()` for additional information.
  75. */
  76. get asyncValidator(): AsyncValidatorFn | null;
  77. set asyncValidator(asyncValidatorFn: AsyncValidatorFn | null);
  78. /**
  79. * The parent control.
  80. */
  81. get parent(): FormGroup | FormArray | null;
  82. /**
  83. * The validation status of the control.
  84. *
  85. * @see `FormControlStatus`
  86. *
  87. * These status values are mutually exclusive, so a control cannot be
  88. * both valid AND invalid or invalid AND disabled.
  89. */
  90. readonly status: FormControlStatus;
  91. /**
  92. * A control is `valid` when its `status` is `VALID`.
  93. *
  94. * @see {@link AbstractControl.status}
  95. *
  96. * @returns True if the control has passed all of its validation tests,
  97. * false otherwise.
  98. */
  99. get valid(): boolean;
  100. /**
  101. * A control is `invalid` when its `status` is `INVALID`.
  102. *
  103. * @see {@link AbstractControl.status}
  104. *
  105. * @returns True if this control has failed one or more of its validation checks,
  106. * false otherwise.
  107. */
  108. get invalid(): boolean;
  109. /**
  110. * A control is `pending` when its `status` is `PENDING`.
  111. *
  112. * @see {@link AbstractControl.status}
  113. *
  114. * @returns True if this control is in the process of conducting a validation check,
  115. * false otherwise.
  116. */
  117. get pending(): boolean;
  118. /**
  119. * A control is `disabled` when its `status` is `DISABLED`.
  120. *
  121. * Disabled controls are exempt from validation checks and
  122. * are not included in the aggregate value of their ancestor
  123. * controls.
  124. *
  125. * @see {@link AbstractControl.status}
  126. *
  127. * @returns True if the control is disabled, false otherwise.
  128. */
  129. get disabled(): boolean;
  130. /**
  131. * A control is `enabled` as long as its `status` is not `DISABLED`.
  132. *
  133. * @returns True if the control has any status other than 'DISABLED',
  134. * false if the status is 'DISABLED'.
  135. *
  136. * @see {@link AbstractControl.status}
  137. *
  138. */
  139. get enabled(): boolean;
  140. /**
  141. * An object containing any errors generated by failing validation,
  142. * or null if there are no errors.
  143. */
  144. readonly errors: ValidationErrors | null;
  145. /**
  146. * A control is `pristine` if the user has not yet changed
  147. * the value in the UI.
  148. *
  149. * @returns True if the user has not yet changed the value in the UI; compare `dirty`.
  150. * Programmatic changes to a control's value do not mark it dirty.
  151. */
  152. readonly pristine: boolean;
  153. /**
  154. * A control is `dirty` if the user has changed the value
  155. * in the UI.
  156. *
  157. * @returns True if the user has changed the value of this control in the UI; compare `pristine`.
  158. * Programmatic changes to a control's value do not mark it dirty.
  159. */
  160. get dirty(): boolean;
  161. /**
  162. * True if the control is marked as `touched`.
  163. *
  164. * A control is marked `touched` once the user has triggered
  165. * a `blur` event on it.
  166. */
  167. readonly touched: boolean;
  168. /**
  169. * True if the control has not been marked as touched
  170. *
  171. * A control is `untouched` if the user has not yet triggered
  172. * a `blur` event on it.
  173. */
  174. get untouched(): boolean;
  175. /**
  176. * A multicasting observable that emits an event every time the value of the control changes, in
  177. * the UI or programmatically. It also emits an event each time you call enable() or disable()
  178. * without passing along {emitEvent: false} as a function argument.
  179. *
  180. * **Note**: the emit happens right after a value of this control is updated. The value of a
  181. * parent control (for example if this FormControl is a part of a FormGroup) is updated later, so
  182. * accessing a value of a parent control (using the `value` property) from the callback of this
  183. * event might result in getting a value that has not been updated yet. Subscribe to the
  184. * `valueChanges` event of the parent control instead.
  185. */
  186. readonly valueChanges: Observable<TValue>;
  187. /**
  188. * A multicasting observable that emits an event every time the validation `status` of the control
  189. * recalculates.
  190. *
  191. * @see `FormControlStatus`
  192. * @see {@link AbstractControl.status}
  193. *
  194. */
  195. readonly statusChanges: Observable<FormControlStatus>;
  196. /**
  197. * Reports the update strategy of the `AbstractControl` (meaning
  198. * the event on which the control updates itself).
  199. * Possible values: `'change'` | `'blur'` | `'submit'`
  200. * Default value: `'change'`
  201. */
  202. get updateOn(): FormHooks;
  203. /**
  204. * Sets the synchronous validators that are active on this control. Calling
  205. * this overwrites any existing synchronous validators.
  206. *
  207. * When you add or remove a validator at run time, you must call
  208. * `updateValueAndValidity()` for the new validation to take effect.
  209. *
  210. * If you want to add a new validator without affecting existing ones, consider
  211. * using `addValidators()` method instead.
  212. */
  213. setValidators(validators: ValidatorFn | ValidatorFn[] | null): void;
  214. /**
  215. * Sets the asynchronous validators that are active on this control. Calling this
  216. * overwrites any existing asynchronous validators.
  217. *
  218. * When you add or remove a validator at run time, you must call
  219. * `updateValueAndValidity()` for the new validation to take effect.
  220. *
  221. * If you want to add a new validator without affecting existing ones, consider
  222. * using `addAsyncValidators()` method instead.
  223. */
  224. setAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[] | null): void;
  225. /**
  226. * Add a synchronous validator or validators to this control, without affecting other validators.
  227. *
  228. * When you add or remove a validator at run time, you must call
  229. * `updateValueAndValidity()` for the new validation to take effect.
  230. *
  231. * Adding a validator that already exists will have no effect. If duplicate validator functions
  232. * are present in the `validators` array, only the first instance would be added to a form
  233. * control.
  234. *
  235. * @param validators The new validator function or functions to add to this control.
  236. */
  237. addValidators(validators: ValidatorFn | ValidatorFn[]): void;
  238. /**
  239. * Add an asynchronous validator or validators to this control, without affecting other
  240. * validators.
  241. *
  242. * When you add or remove a validator at run time, you must call
  243. * `updateValueAndValidity()` for the new validation to take effect.
  244. *
  245. * Adding a validator that already exists will have no effect.
  246. *
  247. * @param validators The new asynchronous validator function or functions to add to this control.
  248. */
  249. addAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[]): void;
  250. /**
  251. * Remove a synchronous validator from this control, without affecting other validators.
  252. * Validators are compared by function reference; you must pass a reference to the exact same
  253. * validator function as the one that was originally set. If a provided validator is not found,
  254. * it is ignored.
  255. *
  256. * @usageNotes
  257. *
  258. * ### Reference to a ValidatorFn
  259. *
  260. * ```
  261. * // Reference to the RequiredValidator
  262. * const ctrl = new FormControl<string | null>('', Validators.required);
  263. * ctrl.removeValidators(Validators.required);
  264. *
  265. * // Reference to anonymous function inside MinValidator
  266. * const minValidator = Validators.min(3);
  267. * const ctrl = new FormControl<string | null>('', minValidator);
  268. * expect(ctrl.hasValidator(minValidator)).toEqual(true)
  269. * expect(ctrl.hasValidator(Validators.min(3))).toEqual(false)
  270. *
  271. * ctrl.removeValidators(minValidator);
  272. * ```
  273. *
  274. * When you add or remove a validator at run time, you must call
  275. * `updateValueAndValidity()` for the new validation to take effect.
  276. *
  277. * @param validators The validator or validators to remove.
  278. */
  279. removeValidators(validators: ValidatorFn | ValidatorFn[]): void;
  280. /**
  281. * Remove an asynchronous validator from this control, without affecting other validators.
  282. * Validators are compared by function reference; you must pass a reference to the exact same
  283. * validator function as the one that was originally set. If a provided validator is not found, it
  284. * is ignored.
  285. *
  286. * When you add or remove a validator at run time, you must call
  287. * `updateValueAndValidity()` for the new validation to take effect.
  288. *
  289. * @param validators The asynchronous validator or validators to remove.
  290. */
  291. removeAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[]): void;
  292. /**
  293. * Check whether a synchronous validator function is present on this control. The provided
  294. * validator must be a reference to the exact same function that was provided.
  295. *
  296. * @usageNotes
  297. *
  298. * ### Reference to a ValidatorFn
  299. *
  300. * ```
  301. * // Reference to the RequiredValidator
  302. * const ctrl = new FormControl<number | null>(0, Validators.required);
  303. * expect(ctrl.hasValidator(Validators.required)).toEqual(true)
  304. *
  305. * // Reference to anonymous function inside MinValidator
  306. * const minValidator = Validators.min(3);
  307. * const ctrl = new FormControl<number | null>(0, minValidator);
  308. * expect(ctrl.hasValidator(minValidator)).toEqual(true)
  309. * expect(ctrl.hasValidator(Validators.min(3))).toEqual(false)
  310. * ```
  311. *
  312. * @param validator The validator to check for presence. Compared by function reference.
  313. * @returns Whether the provided validator was found on this control.
  314. */
  315. hasValidator(validator: ValidatorFn): boolean;
  316. /**
  317. * Check whether an asynchronous validator function is present on this control. The provided
  318. * validator must be a reference to the exact same function that was provided.
  319. *
  320. * @param validator The asynchronous validator to check for presence. Compared by function
  321. * reference.
  322. * @returns Whether the provided asynchronous validator was found on this control.
  323. */
  324. hasAsyncValidator(validator: AsyncValidatorFn): boolean;
  325. /**
  326. * Empties out the synchronous validator list.
  327. *
  328. * When you add or remove a validator at run time, you must call
  329. * `updateValueAndValidity()` for the new validation to take effect.
  330. *
  331. */
  332. clearValidators(): void;
  333. /**
  334. * Empties out the async validator list.
  335. *
  336. * When you add or remove a validator at run time, you must call
  337. * `updateValueAndValidity()` for the new validation to take effect.
  338. *
  339. */
  340. clearAsyncValidators(): void;
  341. /**
  342. * Marks the control as `touched`. A control is touched by focus and
  343. * blur events that do not change the value.
  344. *
  345. * @see `markAsUntouched()`
  346. * @see `markAsDirty()`
  347. * @see `markAsPristine()`
  348. *
  349. * @param opts Configuration options that determine how the control propagates changes
  350. * and emits events after marking is applied.
  351. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  352. * marks all direct ancestors. Default is false.
  353. */
  354. markAsTouched(opts?: {
  355. onlySelf?: boolean;
  356. }): void;
  357. /**
  358. * Marks the control and all its descendant controls as `touched`.
  359. * @see `markAsTouched()`
  360. */
  361. markAllAsTouched(): void;
  362. /**
  363. * Marks the control as `untouched`.
  364. *
  365. * If the control has any children, also marks all children as `untouched`
  366. * and recalculates the `touched` status of all parent controls.
  367. *
  368. * @see `markAsTouched()`
  369. * @see `markAsDirty()`
  370. * @see `markAsPristine()`
  371. *
  372. * @param opts Configuration options that determine how the control propagates changes
  373. * and emits events after the marking is applied.
  374. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  375. * marks all direct ancestors. Default is false.
  376. */
  377. markAsUntouched(opts?: {
  378. onlySelf?: boolean;
  379. }): void;
  380. /**
  381. * Marks the control as `dirty`. A control becomes dirty when
  382. * the control's value is changed through the UI; compare `markAsTouched`.
  383. *
  384. * @see `markAsTouched()`
  385. * @see `markAsUntouched()`
  386. * @see `markAsPristine()`
  387. *
  388. * @param opts Configuration options that determine how the control propagates changes
  389. * and emits events after marking is applied.
  390. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  391. * marks all direct ancestors. Default is false.
  392. */
  393. markAsDirty(opts?: {
  394. onlySelf?: boolean;
  395. }): void;
  396. /**
  397. * Marks the control as `pristine`.
  398. *
  399. * If the control has any children, marks all children as `pristine`,
  400. * and recalculates the `pristine` status of all parent
  401. * controls.
  402. *
  403. * @see `markAsTouched()`
  404. * @see `markAsUntouched()`
  405. * @see `markAsDirty()`
  406. *
  407. * @param opts Configuration options that determine how the control emits events after
  408. * marking is applied.
  409. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  410. * marks all direct ancestors. Default is false.
  411. */
  412. markAsPristine(opts?: {
  413. onlySelf?: boolean;
  414. }): void;
  415. /**
  416. * Marks the control as `pending`.
  417. *
  418. * A control is pending while the control performs async validation.
  419. *
  420. * @see {@link AbstractControl.status}
  421. *
  422. * @param opts Configuration options that determine how the control propagates changes and
  423. * emits events after marking is applied.
  424. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  425. * marks all direct ancestors. Default is false.
  426. * * `emitEvent`: When true or not supplied (the default), the `statusChanges`
  427. * observable emits an event with the latest status the control is marked pending.
  428. * When false, no events are emitted.
  429. *
  430. */
  431. markAsPending(opts?: {
  432. onlySelf?: boolean;
  433. emitEvent?: boolean;
  434. }): void;
  435. /**
  436. * Disables the control. This means the control is exempt from validation checks and
  437. * excluded from the aggregate value of any parent. Its status is `DISABLED`.
  438. *
  439. * If the control has children, all children are also disabled.
  440. *
  441. * @see {@link AbstractControl.status}
  442. *
  443. * @param opts Configuration options that determine how the control propagates
  444. * changes and emits events after the control is disabled.
  445. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  446. * marks all direct ancestors. Default is false.
  447. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  448. * `valueChanges`
  449. * observables emit events with the latest status and value when the control is disabled.
  450. * When false, no events are emitted.
  451. */
  452. disable(opts?: {
  453. onlySelf?: boolean;
  454. emitEvent?: boolean;
  455. }): void;
  456. /**
  457. * Enables the control. This means the control is included in validation checks and
  458. * the aggregate value of its parent. Its status recalculates based on its value and
  459. * its validators.
  460. *
  461. * By default, if the control has children, all children are enabled.
  462. *
  463. * @see {@link AbstractControl.status}
  464. *
  465. * @param opts Configure options that control how the control propagates changes and
  466. * emits events when marked as untouched
  467. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  468. * marks all direct ancestors. Default is false.
  469. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  470. * `valueChanges`
  471. * observables emit events with the latest status and value when the control is enabled.
  472. * When false, no events are emitted.
  473. */
  474. enable(opts?: {
  475. onlySelf?: boolean;
  476. emitEvent?: boolean;
  477. }): void;
  478. private _updateAncestors;
  479. /**
  480. * Sets the parent of the control
  481. *
  482. * @param parent The new parent.
  483. */
  484. setParent(parent: FormGroup | FormArray | null): void;
  485. /**
  486. * Sets the value of the control. Abstract method (implemented in sub-classes).
  487. */
  488. abstract setValue(value: TRawValue, options?: Object): void;
  489. /**
  490. * Patches the value of the control. Abstract method (implemented in sub-classes).
  491. */
  492. abstract patchValue(value: TValue, options?: Object): void;
  493. /**
  494. * Resets the control. Abstract method (implemented in sub-classes).
  495. */
  496. abstract reset(value?: TValue, options?: Object): void;
  497. /**
  498. * The raw value of this control. For most control implementations, the raw value will include
  499. * disabled children.
  500. */
  501. getRawValue(): any;
  502. /**
  503. * Recalculates the value and validation status of the control.
  504. *
  505. * By default, it also updates the value and validity of its ancestors.
  506. *
  507. * @param opts Configuration options determine how the control propagates changes and emits events
  508. * after updates and validity checks are applied.
  509. * * `onlySelf`: When true, only update this control. When false or not supplied,
  510. * update all direct ancestors. Default is false.
  511. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  512. * `valueChanges`
  513. * observables emit events with the latest status and value when the control is updated.
  514. * When false, no events are emitted.
  515. */
  516. updateValueAndValidity(opts?: {
  517. onlySelf?: boolean;
  518. emitEvent?: boolean;
  519. }): void;
  520. private _setInitialStatus;
  521. private _runValidator;
  522. private _runAsyncValidator;
  523. private _cancelExistingSubscription;
  524. /**
  525. * Sets errors on a form control when running validations manually, rather than automatically.
  526. *
  527. * Calling `setErrors` also updates the validity of the parent control.
  528. *
  529. * @param opts Configuration options that determine how the control propagates
  530. * changes and emits events after the control errors are set.
  531. * * `emitEvent`: When true or not supplied (the default), the `statusChanges`
  532. * observable emits an event after the errors are set.
  533. *
  534. * @usageNotes
  535. *
  536. * ### Manually set the errors for a control
  537. *
  538. * ```
  539. * const login = new FormControl('someLogin');
  540. * login.setErrors({
  541. * notUnique: true
  542. * });
  543. *
  544. * expect(login.valid).toEqual(false);
  545. * expect(login.errors).toEqual({ notUnique: true });
  546. *
  547. * login.setValue('someOtherLogin');
  548. *
  549. * expect(login.valid).toEqual(true);
  550. * ```
  551. */
  552. setErrors(errors: ValidationErrors | null, opts?: {
  553. emitEvent?: boolean;
  554. }): void;
  555. /**
  556. * Retrieves a child control given the control's name or path.
  557. *
  558. * This signature for get supports strings and `const` arrays (`.get(['foo', 'bar'] as const)`).
  559. */
  560. get<P extends string | (readonly (string | number)[])>(path: P): AbstractControl<ɵGetProperty<TRawValue, P>> | null;
  561. /**
  562. * Retrieves a child control given the control's name or path.
  563. *
  564. * This signature for `get` supports non-const (mutable) arrays. Inferred type
  565. * information will not be as robust, so prefer to pass a `readonly` array if possible.
  566. */
  567. get<P extends string | Array<string | number>>(path: P): AbstractControl<ɵGetProperty<TRawValue, P>> | null;
  568. /**
  569. * @description
  570. * Reports error data for the control with the given path.
  571. *
  572. * @param errorCode The code of the error to check
  573. * @param path A list of control names that designates how to move from the current control
  574. * to the control that should be queried for errors.
  575. *
  576. * @usageNotes
  577. * For example, for the following `FormGroup`:
  578. *
  579. * ```
  580. * form = new FormGroup({
  581. * address: new FormGroup({ street: new FormControl() })
  582. * });
  583. * ```
  584. *
  585. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  586. *
  587. * It can be provided to this method in one of two formats:
  588. *
  589. * 1. An array of string control names, e.g. `['address', 'street']`
  590. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  591. *
  592. * @returns error data for that particular error. If the control or error is not present,
  593. * null is returned.
  594. */
  595. getError(errorCode: string, path?: Array<string | number> | string): any;
  596. /**
  597. * @description
  598. * Reports whether the control with the given path has the error specified.
  599. *
  600. * @param errorCode The code of the error to check
  601. * @param path A list of control names that designates how to move from the current control
  602. * to the control that should be queried for errors.
  603. *
  604. * @usageNotes
  605. * For example, for the following `FormGroup`:
  606. *
  607. * ```
  608. * form = new FormGroup({
  609. * address: new FormGroup({ street: new FormControl() })
  610. * });
  611. * ```
  612. *
  613. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  614. *
  615. * It can be provided to this method in one of two formats:
  616. *
  617. * 1. An array of string control names, e.g. `['address', 'street']`
  618. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  619. *
  620. * If no path is given, this method checks for the error on the current control.
  621. *
  622. * @returns whether the given error is present in the control at the given path.
  623. *
  624. * If the control is not present, false is returned.
  625. */
  626. hasError(errorCode: string, path?: Array<string | number> | string): boolean;
  627. /**
  628. * Retrieves the top-level ancestor of this control.
  629. */
  630. get root(): AbstractControl;
  631. private _calculateStatus;
  632. /**
  633. * Internal implementation of the `setValidators` method. Needs to be separated out into a
  634. * different method, because it is called in the constructor and it can break cases where
  635. * a control is extended.
  636. */
  637. private _assignValidators;
  638. /**
  639. * Internal implementation of the `setAsyncValidators` method. Needs to be separated out into a
  640. * different method, because it is called in the constructor and it can break cases where
  641. * a control is extended.
  642. */
  643. private _assignAsyncValidators;
  644. }
  645. /**
  646. * @description
  647. * Base class for control directives.
  648. *
  649. * This class is only used internally in the `ReactiveFormsModule` and the `FormsModule`.
  650. *
  651. * @publicApi
  652. */
  653. export declare abstract class AbstractControlDirective {
  654. /**
  655. * @description
  656. * A reference to the underlying control.
  657. *
  658. * @returns the control that backs this directive. Most properties fall through to that instance.
  659. */
  660. abstract get control(): AbstractControl | null;
  661. /**
  662. * @description
  663. * Reports the value of the control if it is present, otherwise null.
  664. */
  665. get value(): any;
  666. /**
  667. * @description
  668. * Reports whether the control is valid. A control is considered valid if no
  669. * validation errors exist with the current value.
  670. * If the control is not present, null is returned.
  671. */
  672. get valid(): boolean | null;
  673. /**
  674. * @description
  675. * Reports whether the control is invalid, meaning that an error exists in the input value.
  676. * If the control is not present, null is returned.
  677. */
  678. get invalid(): boolean | null;
  679. /**
  680. * @description
  681. * Reports whether a control is pending, meaning that that async validation is occurring and
  682. * errors are not yet available for the input value. If the control is not present, null is
  683. * returned.
  684. */
  685. get pending(): boolean | null;
  686. /**
  687. * @description
  688. * Reports whether the control is disabled, meaning that the control is disabled
  689. * in the UI and is exempt from validation checks and excluded from aggregate
  690. * values of ancestor controls. If the control is not present, null is returned.
  691. */
  692. get disabled(): boolean | null;
  693. /**
  694. * @description
  695. * Reports whether the control is enabled, meaning that the control is included in ancestor
  696. * calculations of validity or value. If the control is not present, null is returned.
  697. */
  698. get enabled(): boolean | null;
  699. /**
  700. * @description
  701. * Reports the control's validation errors. If the control is not present, null is returned.
  702. */
  703. get errors(): ValidationErrors | null;
  704. /**
  705. * @description
  706. * Reports whether the control is pristine, meaning that the user has not yet changed
  707. * the value in the UI. If the control is not present, null is returned.
  708. */
  709. get pristine(): boolean | null;
  710. /**
  711. * @description
  712. * Reports whether the control is dirty, meaning that the user has changed
  713. * the value in the UI. If the control is not present, null is returned.
  714. */
  715. get dirty(): boolean | null;
  716. /**
  717. * @description
  718. * Reports whether the control is touched, meaning that the user has triggered
  719. * a `blur` event on it. If the control is not present, null is returned.
  720. */
  721. get touched(): boolean | null;
  722. /**
  723. * @description
  724. * Reports the validation status of the control. Possible values include:
  725. * 'VALID', 'INVALID', 'DISABLED', and 'PENDING'.
  726. * If the control is not present, null is returned.
  727. */
  728. get status(): string | null;
  729. /**
  730. * @description
  731. * Reports whether the control is untouched, meaning that the user has not yet triggered
  732. * a `blur` event on it. If the control is not present, null is returned.
  733. */
  734. get untouched(): boolean | null;
  735. /**
  736. * @description
  737. * Returns a multicasting observable that emits a validation status whenever it is
  738. * calculated for the control. If the control is not present, null is returned.
  739. */
  740. get statusChanges(): Observable<any> | null;
  741. /**
  742. * @description
  743. * Returns a multicasting observable of value changes for the control that emits every time the
  744. * value of the control changes in the UI or programmatically.
  745. * If the control is not present, null is returned.
  746. */
  747. get valueChanges(): Observable<any> | null;
  748. /**
  749. * @description
  750. * Returns an array that represents the path from the top-level form to this control.
  751. * Each index is the string name of the control on that level.
  752. */
  753. get path(): string[] | null;
  754. /**
  755. * Contains the result of merging synchronous validators into a single validator function
  756. * (combined using `Validators.compose`).
  757. */
  758. private _composedValidatorFn;
  759. /**
  760. * Contains the result of merging asynchronous validators into a single validator function
  761. * (combined using `Validators.composeAsync`).
  762. */
  763. private _composedAsyncValidatorFn;
  764. /**
  765. * @description
  766. * Synchronous validator function composed of all the synchronous validators registered with this
  767. * directive.
  768. */
  769. get validator(): ValidatorFn | null;
  770. /**
  771. * @description
  772. * Asynchronous validator function composed of all the asynchronous validators registered with
  773. * this directive.
  774. */
  775. get asyncValidator(): AsyncValidatorFn | null;
  776. private _onDestroyCallbacks;
  777. /**
  778. * @description
  779. * Resets the control with the provided value if the control is present.
  780. */
  781. reset(value?: any): void;
  782. /**
  783. * @description
  784. * Reports whether the control with the given path has the error specified.
  785. *
  786. * @param errorCode The code of the error to check
  787. * @param path A list of control names that designates how to move from the current control
  788. * to the control that should be queried for errors.
  789. *
  790. * @usageNotes
  791. * For example, for the following `FormGroup`:
  792. *
  793. * ```
  794. * form = new FormGroup({
  795. * address: new FormGroup({ street: new FormControl() })
  796. * });
  797. * ```
  798. *
  799. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  800. *
  801. * It can be provided to this method in one of two formats:
  802. *
  803. * 1. An array of string control names, e.g. `['address', 'street']`
  804. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  805. *
  806. * If no path is given, this method checks for the error on the current control.
  807. *
  808. * @returns whether the given error is present in the control at the given path.
  809. *
  810. * If the control is not present, false is returned.
  811. */
  812. hasError(errorCode: string, path?: Array<string | number> | string): boolean;
  813. /**
  814. * @description
  815. * Reports error data for the control with the given path.
  816. *
  817. * @param errorCode The code of the error to check
  818. * @param path A list of control names that designates how to move from the current control
  819. * to the control that should be queried for errors.
  820. *
  821. * @usageNotes
  822. * For example, for the following `FormGroup`:
  823. *
  824. * ```
  825. * form = new FormGroup({
  826. * address: new FormGroup({ street: new FormControl() })
  827. * });
  828. * ```
  829. *
  830. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  831. *
  832. * It can be provided to this method in one of two formats:
  833. *
  834. * 1. An array of string control names, e.g. `['address', 'street']`
  835. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  836. *
  837. * @returns error data for that particular error. If the control or error is not present,
  838. * null is returned.
  839. */
  840. getError(errorCode: string, path?: Array<string | number> | string): any;
  841. }
  842. /**
  843. * Interface for options provided to an `AbstractControl`.
  844. *
  845. * @publicApi
  846. */
  847. export declare interface AbstractControlOptions {
  848. /**
  849. * @description
  850. * The list of validators applied to a control.
  851. */
  852. validators?: ValidatorFn | ValidatorFn[] | null;
  853. /**
  854. * @description
  855. * The list of async validators applied to control.
  856. */
  857. asyncValidators?: AsyncValidatorFn | AsyncValidatorFn[] | null;
  858. /**
  859. * @description
  860. * The event name for control to update upon.
  861. */
  862. updateOn?: 'change' | 'blur' | 'submit';
  863. }
  864. declare class AbstractControlStatus {
  865. private _cd;
  866. constructor(cd: AbstractControlDirective | null);
  867. protected get isTouched(): boolean;
  868. protected get isUntouched(): boolean;
  869. protected get isPristine(): boolean;
  870. protected get isDirty(): boolean;
  871. protected get isValid(): boolean;
  872. protected get isInvalid(): boolean;
  873. protected get isPending(): boolean;
  874. protected get isSubmitted(): boolean;
  875. }
  876. /**
  877. * @description
  878. * A base class for code shared between the `NgModelGroup` and `FormGroupName` directives.
  879. *
  880. * @publicApi
  881. */
  882. export declare class AbstractFormGroupDirective extends ControlContainer implements OnInit, OnDestroy {
  883. /** @nodoc */
  884. ngOnInit(): void;
  885. /** @nodoc */
  886. ngOnDestroy(): void;
  887. /**
  888. * @description
  889. * The `FormGroup` bound to this directive.
  890. */
  891. get control(): FormGroup;
  892. /**
  893. * @description
  894. * The path to this group from the top-level directive.
  895. */
  896. get path(): string[];
  897. /**
  898. * @description
  899. * The top-level directive for this group if present, otherwise null.
  900. */
  901. get formDirective(): Form | null;
  902. static ɵfac: i0.ɵɵFactoryDeclaration<AbstractFormGroupDirective, never>;
  903. static ɵdir: i0.ɵɵDirectiveDeclaration<AbstractFormGroupDirective, never, never, {}, {}, never, never, false, never>;
  904. }
  905. /**
  906. * A base class for Validator-based Directives. The class contains common logic shared across such
  907. * Directives.
  908. *
  909. * For internal use only, this class is not intended for use outside of the Forms package.
  910. */
  911. declare abstract class AbstractValidatorDirective implements Validator, OnChanges {
  912. private _validator;
  913. private _onChange;
  914. /** @nodoc */
  915. ngOnChanges(changes: SimpleChanges): void;
  916. /** @nodoc */
  917. validate(control: AbstractControl): ValidationErrors | null;
  918. /** @nodoc */
  919. registerOnValidatorChange(fn: () => void): void;
  920. /**
  921. * @description
  922. * Determines whether this validator should be active or not based on an input.
  923. * Base class implementation checks whether an input is defined (if the value is different from
  924. * `null` and `undefined`). Validator classes that extend this base class can override this
  925. * function with the logic specific to a particular validator directive.
  926. */
  927. enabled(input: unknown): boolean;
  928. static ɵfac: i0.ɵɵFactoryDeclaration<AbstractValidatorDirective, never>;
  929. static ɵdir: i0.ɵɵDirectiveDeclaration<AbstractValidatorDirective, never, never, {}, {}, never, never, false, never>;
  930. }
  931. /**
  932. * @description
  933. * An interface implemented by classes that perform asynchronous validation.
  934. *
  935. * @usageNotes
  936. *
  937. * ### Provide a custom async validator directive
  938. *
  939. * The following example implements the `AsyncValidator` interface to create an
  940. * async validator directive with a custom error key.
  941. *
  942. * ```typescript
  943. * import { of } from 'rxjs';
  944. *
  945. * @Directive({
  946. * selector: '[customAsyncValidator]',
  947. * providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi:
  948. * true}]
  949. * })
  950. * class CustomAsyncValidatorDirective implements AsyncValidator {
  951. * validate(control: AbstractControl): Observable<ValidationErrors|null> {
  952. * return of({'custom': true});
  953. * }
  954. * }
  955. * ```
  956. *
  957. * @publicApi
  958. */
  959. export declare interface AsyncValidator extends Validator {
  960. /**
  961. * @description
  962. * Method that performs async validation against the provided control.
  963. *
  964. * @param control The control to validate against.
  965. *
  966. * @returns A promise or observable that resolves a map of validation errors
  967. * if validation fails, otherwise null.
  968. */
  969. validate(control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null>;
  970. }
  971. /**
  972. * @description
  973. * A function that receives a control and returns a Promise or observable
  974. * that emits validation errors if present, otherwise null.
  975. *
  976. * @publicApi
  977. */
  978. export declare interface AsyncValidatorFn {
  979. (control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null>;
  980. }
  981. /**
  982. * Base class for all ControlValueAccessor classes defined in Forms package.
  983. * Contains common logic and utility functions.
  984. *
  985. * Note: this is an *internal-only* class and should not be extended or used directly in
  986. * applications code.
  987. */
  988. declare class BaseControlValueAccessor {
  989. private _renderer;
  990. private _elementRef;
  991. /**
  992. * The registered callback function called when a change or input event occurs on the input
  993. * element.
  994. * @nodoc
  995. */
  996. onChange: (_: any) => void;
  997. /**
  998. * The registered callback function called when a blur event occurs on the input element.
  999. * @nodoc
  1000. */
  1001. onTouched: () => void;
  1002. constructor(_renderer: Renderer2, _elementRef: ElementRef);
  1003. /**
  1004. * Helper method that sets a property on a target element using the current Renderer
  1005. * implementation.
  1006. * @nodoc
  1007. */
  1008. protected setProperty(key: string, value: any): void;
  1009. /**
  1010. * Registers a function called when the control is touched.
  1011. * @nodoc
  1012. */
  1013. registerOnTouched(fn: () => void): void;
  1014. /**
  1015. * Registers a function called when the control value changes.
  1016. * @nodoc
  1017. */
  1018. registerOnChange(fn: (_: any) => {}): void;
  1019. /**
  1020. * Sets the "disabled" property on the range input element.
  1021. * @nodoc
  1022. */
  1023. setDisabledState(isDisabled: boolean): void;
  1024. static ɵfac: i0.ɵɵFactoryDeclaration<BaseControlValueAccessor, never>;
  1025. static ɵdir: i0.ɵɵDirectiveDeclaration<BaseControlValueAccessor, never, never, {}, {}, never, never, false, never>;
  1026. }
  1027. /**
  1028. * Base class for all built-in ControlValueAccessor classes (except DefaultValueAccessor, which is
  1029. * used in case no other CVAs can be found). We use this class to distinguish between default CVA,
  1030. * built-in CVAs and custom CVAs, so that Forms logic can recognize built-in CVAs and treat custom
  1031. * ones with higher priority (when both built-in and custom CVAs are present).
  1032. *
  1033. * Note: this is an *internal-only* class and should not be extended or used directly in
  1034. * applications code.
  1035. */
  1036. declare class BuiltInControlValueAccessor extends BaseControlValueAccessor {
  1037. static ɵfac: i0.ɵɵFactoryDeclaration<BuiltInControlValueAccessor, never>;
  1038. static ɵdir: i0.ɵɵDirectiveDeclaration<BuiltInControlValueAccessor, never, never, {}, {}, never, never, false, never>;
  1039. }
  1040. /**
  1041. * Token to provide to allow SetDisabledState to always be called when a CVA is added, regardless of
  1042. * whether the control is disabled or enabled.
  1043. *
  1044. * @see `FormsModule.withConfig`
  1045. */
  1046. declare const CALL_SET_DISABLED_STATE: InjectionToken<SetDisabledStateOption>;
  1047. /**
  1048. * @description
  1049. * Provider which adds `CheckboxRequiredValidator` to the `NG_VALIDATORS` multi-provider list.
  1050. */
  1051. declare const CHECKBOX_REQUIRED_VALIDATOR: Provider;
  1052. /**
  1053. * @description
  1054. * A `ControlValueAccessor` for writing a value and listening to changes on a checkbox input
  1055. * element.
  1056. *
  1057. * @usageNotes
  1058. *
  1059. * ### Using a checkbox with a reactive form.
  1060. *
  1061. * The following example shows how to use a checkbox with a reactive form.
  1062. *
  1063. * ```ts
  1064. * const rememberLoginControl = new FormControl();
  1065. * ```
  1066. *
  1067. * ```
  1068. * <input type="checkbox" [formControl]="rememberLoginControl">
  1069. * ```
  1070. *
  1071. * @ngModule ReactiveFormsModule
  1072. * @ngModule FormsModule
  1073. * @publicApi
  1074. */
  1075. export declare class CheckboxControlValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor {
  1076. /**
  1077. * Sets the "checked" property on the input element.
  1078. * @nodoc
  1079. */
  1080. writeValue(value: any): void;
  1081. static ɵfac: i0.ɵɵFactoryDeclaration<CheckboxControlValueAccessor, never>;
  1082. static ɵdir: i0.ɵɵDirectiveDeclaration<CheckboxControlValueAccessor, "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]", never, {}, {}, never, never, false, never>;
  1083. }
  1084. /**
  1085. * A Directive that adds the `required` validator to checkbox controls marked with the
  1086. * `required` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  1087. *
  1088. * @see [Form Validation](guide/form-validation)
  1089. *
  1090. * @usageNotes
  1091. *
  1092. * ### Adding a required checkbox validator using template-driven forms
  1093. *
  1094. * The following example shows how to add a checkbox required validator to an input attached to an
  1095. * ngModel binding.
  1096. *
  1097. * ```
  1098. * <input type="checkbox" name="active" ngModel required>
  1099. * ```
  1100. *
  1101. * @publicApi
  1102. * @ngModule FormsModule
  1103. * @ngModule ReactiveFormsModule
  1104. */
  1105. export declare class CheckboxRequiredValidator extends RequiredValidator {
  1106. static ɵfac: i0.ɵɵFactoryDeclaration<CheckboxRequiredValidator, never>;
  1107. static ɵdir: i0.ɵɵDirectiveDeclaration<CheckboxRequiredValidator, "input[type=checkbox][required][formControlName],input[type=checkbox][required][formControl],input[type=checkbox][required][ngModel]", never, {}, {}, never, never, false, never>;
  1108. }
  1109. /**
  1110. * @description
  1111. * Provide this token to control if form directives buffer IME input until
  1112. * the "compositionend" event occurs.
  1113. * @publicApi
  1114. */
  1115. export declare const COMPOSITION_BUFFER_MODE: InjectionToken<boolean>;
  1116. /**
  1117. * ControlConfig<T> is a tuple containing a value of type T, plus optional validators and async
  1118. * validators.
  1119. *
  1120. * @publicApi
  1121. */
  1122. export declare type ControlConfig<T> = [T | FormControlState<T>, (ValidatorFn | (ValidatorFn[]))?, (AsyncValidatorFn | AsyncValidatorFn[])?];
  1123. /**
  1124. * @description
  1125. * A base class for directives that contain multiple registered instances of `NgControl`.
  1126. * Only used by the forms module.
  1127. *
  1128. * @publicApi
  1129. */
  1130. export declare abstract class ControlContainer extends AbstractControlDirective {
  1131. /**
  1132. * @description
  1133. * The name for the control
  1134. */
  1135. name: string | number | null;
  1136. /**
  1137. * @description
  1138. * The top-level form directive for the control.
  1139. */
  1140. get formDirective(): Form | null;
  1141. /**
  1142. * @description
  1143. * The path to this group.
  1144. */
  1145. get path(): string[] | null;
  1146. }
  1147. /**
  1148. * @description
  1149. * Defines an interface that acts as a bridge between the Angular forms API and a
  1150. * native element in the DOM.
  1151. *
  1152. * Implement this interface to create a custom form control directive
  1153. * that integrates with Angular forms.
  1154. *
  1155. * @see DefaultValueAccessor
  1156. *
  1157. * @publicApi
  1158. */
  1159. export declare interface ControlValueAccessor {
  1160. /**
  1161. * @description
  1162. * Writes a new value to the element.
  1163. *
  1164. * This method is called by the forms API to write to the view when programmatic
  1165. * changes from model to view are requested.
  1166. *
  1167. * @usageNotes
  1168. * ### Write a value to the element
  1169. *
  1170. * The following example writes a value to the native DOM element.
  1171. *
  1172. * ```ts
  1173. * writeValue(value: any): void {
  1174. * this._renderer.setProperty(this._elementRef.nativeElement, 'value', value);
  1175. * }
  1176. * ```
  1177. *
  1178. * @param obj The new value for the element
  1179. */
  1180. writeValue(obj: any): void;
  1181. /**
  1182. * @description
  1183. * Registers a callback function that is called when the control's value
  1184. * changes in the UI.
  1185. *
  1186. * This method is called by the forms API on initialization to update the form
  1187. * model when values propagate from the view to the model.
  1188. *
  1189. * When implementing the `registerOnChange` method in your own value accessor,
  1190. * save the given function so your class calls it at the appropriate time.
  1191. *
  1192. * @usageNotes
  1193. * ### Store the change function
  1194. *
  1195. * The following example stores the provided function as an internal method.
  1196. *
  1197. * ```ts
  1198. * registerOnChange(fn: (_: any) => void): void {
  1199. * this._onChange = fn;
  1200. * }
  1201. * ```
  1202. *
  1203. * When the value changes in the UI, call the registered
  1204. * function to allow the forms API to update itself:
  1205. *
  1206. * ```ts
  1207. * host: {
  1208. * '(change)': '_onChange($event.target.value)'
  1209. * }
  1210. * ```
  1211. *
  1212. * @param fn The callback function to register
  1213. */
  1214. registerOnChange(fn: any): void;
  1215. /**
  1216. * @description
  1217. * Registers a callback function that is called by the forms API on initialization
  1218. * to update the form model on blur.
  1219. *
  1220. * When implementing `registerOnTouched` in your own value accessor, save the given
  1221. * function so your class calls it when the control should be considered
  1222. * blurred or "touched".
  1223. *
  1224. * @usageNotes
  1225. * ### Store the callback function
  1226. *
  1227. * The following example stores the provided function as an internal method.
  1228. *
  1229. * ```ts
  1230. * registerOnTouched(fn: any): void {
  1231. * this._onTouched = fn;
  1232. * }
  1233. * ```
  1234. *
  1235. * On blur (or equivalent), your class should call the registered function to allow
  1236. * the forms API to update itself:
  1237. *
  1238. * ```ts
  1239. * host: {
  1240. * '(blur)': '_onTouched()'
  1241. * }
  1242. * ```
  1243. *
  1244. * @param fn The callback function to register
  1245. */
  1246. registerOnTouched(fn: any): void;
  1247. /**
  1248. * @description
  1249. * Function that is called by the forms API when the control status changes to
  1250. * or from 'DISABLED'. Depending on the status, it enables or disables the
  1251. * appropriate DOM element.
  1252. *
  1253. * @usageNotes
  1254. * The following is an example of writing the disabled property to a native DOM element:
  1255. *
  1256. * ```ts
  1257. * setDisabledState(isDisabled: boolean): void {
  1258. * this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  1259. * }
  1260. * ```
  1261. *
  1262. * @param isDisabled The disabled status to set on the element
  1263. */
  1264. setDisabledState?(isDisabled: boolean): void;
  1265. }
  1266. declare const DEFAULT_VALUE_ACCESSOR: any;
  1267. /**
  1268. * The default `ControlValueAccessor` for writing a value and listening to changes on input
  1269. * elements. The accessor is used by the `FormControlDirective`, `FormControlName`, and
  1270. * `NgModel` directives.
  1271. *
  1272. * {@searchKeywords ngDefaultControl}
  1273. *
  1274. * @usageNotes
  1275. *
  1276. * ### Using the default value accessor
  1277. *
  1278. * The following example shows how to use an input element that activates the default value accessor
  1279. * (in this case, a text field).
  1280. *
  1281. * ```ts
  1282. * const firstNameControl = new FormControl();
  1283. * ```
  1284. *
  1285. * ```
  1286. * <input type="text" [formControl]="firstNameControl">
  1287. * ```
  1288. *
  1289. * This value accessor is used by default for `<input type="text">` and `<textarea>` elements, but
  1290. * you could also use it for custom components that have similar behavior and do not require special
  1291. * processing. In order to attach the default value accessor to a custom element, add the
  1292. * `ngDefaultControl` attribute as shown below.
  1293. *
  1294. * ```
  1295. * <custom-input-component ngDefaultControl [(ngModel)]="value"></custom-input-component>
  1296. * ```
  1297. *
  1298. * @ngModule ReactiveFormsModule
  1299. * @ngModule FormsModule
  1300. * @publicApi
  1301. */
  1302. export declare class DefaultValueAccessor extends BaseControlValueAccessor implements ControlValueAccessor {
  1303. private _compositionMode;
  1304. /** Whether the user is creating a composition string (IME events). */
  1305. private _composing;
  1306. constructor(renderer: Renderer2, elementRef: ElementRef, _compositionMode: boolean);
  1307. /**
  1308. * Sets the "value" property on the input element.
  1309. * @nodoc
  1310. */
  1311. writeValue(value: any): void;
  1312. static ɵfac: i0.ɵɵFactoryDeclaration<DefaultValueAccessor, [null, null, { optional: true; }]>;
  1313. static ɵdir: i0.ɵɵDirectiveDeclaration<DefaultValueAccessor, "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]", never, {}, {}, never, never, false, never>;
  1314. }
  1315. /**
  1316. * @description
  1317. * Provider which adds `EmailValidator` to the `NG_VALIDATORS` multi-provider list.
  1318. */
  1319. declare const EMAIL_VALIDATOR: any;
  1320. /**
  1321. * A directive that adds the `email` validator to controls marked with the
  1322. * `email` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  1323. *
  1324. * The email validation is based on the WHATWG HTML specification with some enhancements to
  1325. * incorporate more RFC rules. More information can be found on the [Validators.email
  1326. * page](api/forms/Validators#email).
  1327. *
  1328. * @see [Form Validation](guide/form-validation)
  1329. *
  1330. * @usageNotes
  1331. *
  1332. * ### Adding an email validator
  1333. *
  1334. * The following example shows how to add an email validator to an input attached to an ngModel
  1335. * binding.
  1336. *
  1337. * ```
  1338. * <input type="email" name="email" ngModel email>
  1339. * <input type="email" name="email" ngModel email="true">
  1340. * <input type="email" name="email" ngModel [email]="true">
  1341. * ```
  1342. *
  1343. * @publicApi
  1344. * @ngModule FormsModule
  1345. * @ngModule ReactiveFormsModule
  1346. */
  1347. export declare class EmailValidator extends AbstractValidatorDirective {
  1348. /**
  1349. * @description
  1350. * Tracks changes to the email attribute bound to this directive.
  1351. */
  1352. email: boolean | string;
  1353. /** @nodoc */
  1354. enabled(input: boolean): boolean;
  1355. static ɵfac: i0.ɵɵFactoryDeclaration<EmailValidator, never>;
  1356. static ɵdir: i0.ɵɵDirectiveDeclaration<EmailValidator, "[email][formControlName],[email][formControl],[email][ngModel]", never, { "email": { "alias": "email"; "required": false; }; }, {}, never, never, false, never>;
  1357. }
  1358. /**
  1359. * @description
  1360. * An interface implemented by `FormGroupDirective` and `NgForm` directives.
  1361. *
  1362. * Only used by the `ReactiveFormsModule` and `FormsModule`.
  1363. *
  1364. * @publicApi
  1365. */
  1366. export declare interface Form {
  1367. /**
  1368. * @description
  1369. * Add a control to this form.
  1370. *
  1371. * @param dir The control directive to add to the form.
  1372. */
  1373. addControl(dir: NgControl): void;
  1374. /**
  1375. * @description
  1376. * Remove a control from this form.
  1377. *
  1378. * @param dir: The control directive to remove from the form.
  1379. */
  1380. removeControl(dir: NgControl): void;
  1381. /**
  1382. * @description
  1383. * The control directive from which to get the `FormControl`.
  1384. *
  1385. * @param dir: The control directive.
  1386. */
  1387. getControl(dir: NgControl): FormControl;
  1388. /**
  1389. * @description
  1390. * Add a group of controls to this form.
  1391. *
  1392. * @param dir: The control group directive to add.
  1393. */
  1394. addFormGroup(dir: AbstractFormGroupDirective): void;
  1395. /**
  1396. * @description
  1397. * Remove a group of controls to this form.
  1398. *
  1399. * @param dir: The control group directive to remove.
  1400. */
  1401. removeFormGroup(dir: AbstractFormGroupDirective): void;
  1402. /**
  1403. * @description
  1404. * The `FormGroup` associated with a particular `AbstractFormGroupDirective`.
  1405. *
  1406. * @param dir: The form group directive from which to get the `FormGroup`.
  1407. */
  1408. getFormGroup(dir: AbstractFormGroupDirective): FormGroup;
  1409. /**
  1410. * @description
  1411. * Update the model for a particular control with a new value.
  1412. *
  1413. * @param dir: The control directive to update.
  1414. * @param value: The new value for the control.
  1415. */
  1416. updateModel(dir: NgControl, value: any): void;
  1417. }
  1418. /**
  1419. * Tracks the value and validity state of an array of `FormControl`,
  1420. * `FormGroup` or `FormArray` instances.
  1421. *
  1422. * A `FormArray` aggregates the values of each child `FormControl` into an array.
  1423. * It calculates its status by reducing the status values of its children. For example, if one of
  1424. * the controls in a `FormArray` is invalid, the entire array becomes invalid.
  1425. *
  1426. * `FormArray` accepts one generic argument, which is the type of the controls inside.
  1427. * If you need a heterogenous array, use {@link UntypedFormArray}.
  1428. *
  1429. * `FormArray` is one of the four fundamental building blocks used to define forms in Angular,
  1430. * along with `FormControl`, `FormGroup`, and `FormRecord`.
  1431. *
  1432. * @usageNotes
  1433. *
  1434. * ### Create an array of form controls
  1435. *
  1436. * ```
  1437. * const arr = new FormArray([
  1438. * new FormControl('Nancy', Validators.minLength(2)),
  1439. * new FormControl('Drew'),
  1440. * ]);
  1441. *
  1442. * console.log(arr.value); // ['Nancy', 'Drew']
  1443. * console.log(arr.status); // 'VALID'
  1444. * ```
  1445. *
  1446. * ### Create a form array with array-level validators
  1447. *
  1448. * You include array-level validators and async validators. These come in handy
  1449. * when you want to perform validation that considers the value of more than one child
  1450. * control.
  1451. *
  1452. * The two types of validators are passed in separately as the second and third arg
  1453. * respectively, or together as part of an options object.
  1454. *
  1455. * ```
  1456. * const arr = new FormArray([
  1457. * new FormControl('Nancy'),
  1458. * new FormControl('Drew')
  1459. * ], {validators: myValidator, asyncValidators: myAsyncValidator});
  1460. * ```
  1461. *
  1462. * ### Set the updateOn property for all controls in a form array
  1463. *
  1464. * The options object is used to set a default value for each child
  1465. * control's `updateOn` property. If you set `updateOn` to `'blur'` at the
  1466. * array level, all child controls default to 'blur', unless the child
  1467. * has explicitly specified a different `updateOn` value.
  1468. *
  1469. * ```ts
  1470. * const arr = new FormArray([
  1471. * new FormControl()
  1472. * ], {updateOn: 'blur'});
  1473. * ```
  1474. *
  1475. * ### Adding or removing controls from a form array
  1476. *
  1477. * To change the controls in the array, use the `push`, `insert`, `removeAt` or `clear` methods
  1478. * in `FormArray` itself. These methods ensure the controls are properly tracked in the
  1479. * form's hierarchy. Do not modify the array of `AbstractControl`s used to instantiate
  1480. * the `FormArray` directly, as that result in strange and unexpected behavior such
  1481. * as broken change detection.
  1482. *
  1483. * @publicApi
  1484. */
  1485. export declare class FormArray<TControl extends AbstractControl<any> = any> extends AbstractControl<ɵTypedOrUntyped<TControl, ɵFormArrayValue<TControl>, any>, ɵTypedOrUntyped<TControl, ɵFormArrayRawValue<TControl>, any>> {
  1486. /**
  1487. * Creates a new `FormArray` instance.
  1488. *
  1489. * @param controls An array of child controls. Each child control is given an index
  1490. * where it is registered.
  1491. *
  1492. * @param validatorOrOpts A synchronous validator function, or an array of
  1493. * such functions, or an `AbstractControlOptions` object that contains validation functions
  1494. * and a validation trigger.
  1495. *
  1496. * @param asyncValidator A single async validator or array of async validator functions
  1497. *
  1498. */
  1499. constructor(controls: Array<TControl>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
  1500. controls: ɵTypedOrUntyped<TControl, Array<TControl>, Array<AbstractControl<any>>>;
  1501. /**
  1502. * Get the `AbstractControl` at the given `index` in the array.
  1503. *
  1504. * @param index Index in the array to retrieve the control. If `index` is negative, it will wrap
  1505. * around from the back, and if index is greatly negative (less than `-length`), the result is
  1506. * undefined. This behavior is the same as `Array.at(index)`.
  1507. */
  1508. at(index: number): ɵTypedOrUntyped<TControl, TControl, AbstractControl<any>>;
  1509. /**
  1510. * Insert a new `AbstractControl` at the end of the array.
  1511. *
  1512. * @param control Form control to be inserted
  1513. * @param options Specifies whether this FormArray instance should emit events after a new
  1514. * control is added.
  1515. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1516. * `valueChanges` observables emit events with the latest status and value when the control is
  1517. * inserted. When false, no events are emitted.
  1518. */
  1519. push(control: TControl, options?: {
  1520. emitEvent?: boolean;
  1521. }): void;
  1522. /**
  1523. * Insert a new `AbstractControl` at the given `index` in the array.
  1524. *
  1525. * @param index Index in the array to insert the control. If `index` is negative, wraps around
  1526. * from the back. If `index` is greatly negative (less than `-length`), prepends to the array.
  1527. * This behavior is the same as `Array.splice(index, 0, control)`.
  1528. * @param control Form control to be inserted
  1529. * @param options Specifies whether this FormArray instance should emit events after a new
  1530. * control is inserted.
  1531. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1532. * `valueChanges` observables emit events with the latest status and value when the control is
  1533. * inserted. When false, no events are emitted.
  1534. */
  1535. insert(index: number, control: TControl, options?: {
  1536. emitEvent?: boolean;
  1537. }): void;
  1538. /**
  1539. * Remove the control at the given `index` in the array.
  1540. *
  1541. * @param index Index in the array to remove the control. If `index` is negative, wraps around
  1542. * from the back. If `index` is greatly negative (less than `-length`), removes the first
  1543. * element. This behavior is the same as `Array.splice(index, 1)`.
  1544. * @param options Specifies whether this FormArray instance should emit events after a
  1545. * control is removed.
  1546. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1547. * `valueChanges` observables emit events with the latest status and value when the control is
  1548. * removed. When false, no events are emitted.
  1549. */
  1550. removeAt(index: number, options?: {
  1551. emitEvent?: boolean;
  1552. }): void;
  1553. /**
  1554. * Replace an existing control.
  1555. *
  1556. * @param index Index in the array to replace the control. If `index` is negative, wraps around
  1557. * from the back. If `index` is greatly negative (less than `-length`), replaces the first
  1558. * element. This behavior is the same as `Array.splice(index, 1, control)`.
  1559. * @param control The `AbstractControl` control to replace the existing control
  1560. * @param options Specifies whether this FormArray instance should emit events after an
  1561. * existing control is replaced with a new one.
  1562. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1563. * `valueChanges` observables emit events with the latest status and value when the control is
  1564. * replaced with a new one. When false, no events are emitted.
  1565. */
  1566. setControl(index: number, control: TControl, options?: {
  1567. emitEvent?: boolean;
  1568. }): void;
  1569. /**
  1570. * Length of the control array.
  1571. */
  1572. get length(): number;
  1573. /**
  1574. * Sets the value of the `FormArray`. It accepts an array that matches
  1575. * the structure of the control.
  1576. *
  1577. * This method performs strict checks, and throws an error if you try
  1578. * to set the value of a control that doesn't exist or if you exclude the
  1579. * value of a control.
  1580. *
  1581. * @usageNotes
  1582. * ### Set the values for the controls in the form array
  1583. *
  1584. * ```
  1585. * const arr = new FormArray([
  1586. * new FormControl(),
  1587. * new FormControl()
  1588. * ]);
  1589. * console.log(arr.value); // [null, null]
  1590. *
  1591. * arr.setValue(['Nancy', 'Drew']);
  1592. * console.log(arr.value); // ['Nancy', 'Drew']
  1593. * ```
  1594. *
  1595. * @param value Array of values for the controls
  1596. * @param options Configure options that determine how the control propagates changes and
  1597. * emits events after the value changes
  1598. *
  1599. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  1600. * is false.
  1601. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1602. * `valueChanges`
  1603. * observables emit events with the latest status and value when the control value is updated.
  1604. * When false, no events are emitted.
  1605. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  1606. * updateValueAndValidity} method.
  1607. */
  1608. setValue(value: ɵFormArrayRawValue<TControl>, options?: {
  1609. onlySelf?: boolean;
  1610. emitEvent?: boolean;
  1611. }): void;
  1612. /**
  1613. * Patches the value of the `FormArray`. It accepts an array that matches the
  1614. * structure of the control, and does its best to match the values to the correct
  1615. * controls in the group.
  1616. *
  1617. * It accepts both super-sets and sub-sets of the array without throwing an error.
  1618. *
  1619. * @usageNotes
  1620. * ### Patch the values for controls in a form array
  1621. *
  1622. * ```
  1623. * const arr = new FormArray([
  1624. * new FormControl(),
  1625. * new FormControl()
  1626. * ]);
  1627. * console.log(arr.value); // [null, null]
  1628. *
  1629. * arr.patchValue(['Nancy']);
  1630. * console.log(arr.value); // ['Nancy', null]
  1631. * ```
  1632. *
  1633. * @param value Array of latest values for the controls
  1634. * @param options Configure options that determine how the control propagates changes and
  1635. * emits events after the value changes
  1636. *
  1637. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  1638. * is false.
  1639. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1640. * `valueChanges` observables emit events with the latest status and value when the control
  1641. * value is updated. When false, no events are emitted. The configuration options are passed to
  1642. * the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
  1643. */
  1644. patchValue(value: ɵFormArrayValue<TControl>, options?: {
  1645. onlySelf?: boolean;
  1646. emitEvent?: boolean;
  1647. }): void;
  1648. /**
  1649. * Resets the `FormArray` and all descendants are marked `pristine` and `untouched`, and the
  1650. * value of all descendants to null or null maps.
  1651. *
  1652. * You reset to a specific form state by passing in an array of states
  1653. * that matches the structure of the control. The state is a standalone value
  1654. * or a form state object with both a value and a disabled status.
  1655. *
  1656. * @usageNotes
  1657. * ### Reset the values in a form array
  1658. *
  1659. * ```ts
  1660. * const arr = new FormArray([
  1661. * new FormControl(),
  1662. * new FormControl()
  1663. * ]);
  1664. * arr.reset(['name', 'last name']);
  1665. *
  1666. * console.log(arr.value); // ['name', 'last name']
  1667. * ```
  1668. *
  1669. * ### Reset the values in a form array and the disabled status for the first control
  1670. *
  1671. * ```
  1672. * arr.reset([
  1673. * {value: 'name', disabled: true},
  1674. * 'last'
  1675. * ]);
  1676. *
  1677. * console.log(arr.value); // ['last']
  1678. * console.log(arr.at(0).status); // 'DISABLED'
  1679. * ```
  1680. *
  1681. * @param value Array of values for the controls
  1682. * @param options Configure options that determine how the control propagates changes and
  1683. * emits events after the value changes
  1684. *
  1685. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  1686. * is false.
  1687. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1688. * `valueChanges`
  1689. * observables emit events with the latest status and value when the control is reset.
  1690. * When false, no events are emitted.
  1691. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  1692. * updateValueAndValidity} method.
  1693. */
  1694. reset(value?: ɵTypedOrUntyped<TControl, ɵFormArrayValue<TControl>, any>, options?: {
  1695. onlySelf?: boolean;
  1696. emitEvent?: boolean;
  1697. }): void;
  1698. /**
  1699. * The aggregate value of the array, including any disabled controls.
  1700. *
  1701. * Reports all values regardless of disabled status.
  1702. */
  1703. getRawValue(): ɵFormArrayRawValue<TControl>;
  1704. /**
  1705. * Remove all controls in the `FormArray`.
  1706. *
  1707. * @param options Specifies whether this FormArray instance should emit events after all
  1708. * controls are removed.
  1709. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  1710. * `valueChanges` observables emit events with the latest status and value when all controls
  1711. * in this FormArray instance are removed. When false, no events are emitted.
  1712. *
  1713. * @usageNotes
  1714. * ### Remove all elements from a FormArray
  1715. *
  1716. * ```ts
  1717. * const arr = new FormArray([
  1718. * new FormControl(),
  1719. * new FormControl()
  1720. * ]);
  1721. * console.log(arr.length); // 2
  1722. *
  1723. * arr.clear();
  1724. * console.log(arr.length); // 0
  1725. * ```
  1726. *
  1727. * It's a simpler and more efficient alternative to removing all elements one by one:
  1728. *
  1729. * ```ts
  1730. * const arr = new FormArray([
  1731. * new FormControl(),
  1732. * new FormControl()
  1733. * ]);
  1734. *
  1735. * while (arr.length) {
  1736. * arr.removeAt(0);
  1737. * }
  1738. * ```
  1739. */
  1740. clear(options?: {
  1741. emitEvent?: boolean;
  1742. }): void;
  1743. private _registerControl;
  1744. }
  1745. /**
  1746. * @description
  1747. *
  1748. * Syncs a nested `FormArray` to a DOM element.
  1749. *
  1750. * This directive is designed to be used with a parent `FormGroupDirective` (selector:
  1751. * `[formGroup]`).
  1752. *
  1753. * It accepts the string name of the nested `FormArray` you want to link, and
  1754. * will look for a `FormArray` registered with that name in the parent
  1755. * `FormGroup` instance you passed into `FormGroupDirective`.
  1756. *
  1757. * @see [Reactive Forms Guide](guide/reactive-forms)
  1758. * @see `AbstractControl`
  1759. *
  1760. * @usageNotes
  1761. *
  1762. * ### Example
  1763. *
  1764. * {@example forms/ts/nestedFormArray/nested_form_array_example.ts region='Component'}
  1765. *
  1766. * @ngModule ReactiveFormsModule
  1767. * @publicApi
  1768. */
  1769. export declare class FormArrayName extends ControlContainer implements OnInit, OnDestroy {
  1770. /**
  1771. * @description
  1772. * Tracks the name of the `FormArray` bound to the directive. The name corresponds
  1773. * to a key in the parent `FormGroup` or `FormArray`.
  1774. * Accepts a name as a string or a number.
  1775. * The name in the form of a string is useful for individual forms,
  1776. * while the numerical form allows for form arrays to be bound
  1777. * to indices when iterating over arrays in a `FormArray`.
  1778. */
  1779. name: string | number | null;
  1780. constructor(parent: ControlContainer, validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[]);
  1781. /**
  1782. * A lifecycle method called when the directive's inputs are initialized. For internal use only.
  1783. * @throws If the directive does not have a valid parent.
  1784. * @nodoc
  1785. */
  1786. ngOnInit(): void;
  1787. /**
  1788. * A lifecycle method called before the directive's instance is destroyed. For internal use only.
  1789. * @nodoc
  1790. */
  1791. ngOnDestroy(): void;
  1792. /**
  1793. * @description
  1794. * The `FormArray` bound to this directive.
  1795. */
  1796. get control(): FormArray;
  1797. /**
  1798. * @description
  1799. * The top-level directive for this group if present, otherwise null.
  1800. */
  1801. get formDirective(): FormGroupDirective | null;
  1802. /**
  1803. * @description
  1804. * Returns an array that represents the path from the top-level form to this control.
  1805. * Each index is the string name of the control on that level.
  1806. */
  1807. get path(): string[];
  1808. private _checkParentType;
  1809. static ɵfac: i0.ɵɵFactoryDeclaration<FormArrayName, [{ optional: true; host: true; skipSelf: true; }, { optional: true; self: true; }, { optional: true; self: true; }]>;
  1810. static ɵdir: i0.ɵɵDirectiveDeclaration<FormArrayName, "[formArrayName]", never, { "name": { "alias": "formArrayName"; "required": false; }; }, {}, never, never, false, never>;
  1811. }
  1812. declare const formArrayNameProvider: any;
  1813. /**
  1814. * @description
  1815. * Creates an `AbstractControl` from a user-specified configuration.
  1816. *
  1817. * The `FormBuilder` provides syntactic sugar that shortens creating instances of a
  1818. * `FormControl`, `FormGroup`, or `FormArray`. It reduces the amount of boilerplate needed to
  1819. * build complex forms.
  1820. *
  1821. * @see [Reactive Forms Guide](guide/reactive-forms)
  1822. *
  1823. * @publicApi
  1824. */
  1825. export declare class FormBuilder {
  1826. private useNonNullable;
  1827. /**
  1828. * @description
  1829. * Returns a FormBuilder in which automatically constructed `FormControl` elements
  1830. * have `{nonNullable: true}` and are non-nullable.
  1831. *
  1832. * **Constructing non-nullable controls**
  1833. *
  1834. * When constructing a control, it will be non-nullable, and will reset to its initial value.
  1835. *
  1836. * ```ts
  1837. * let nnfb = new FormBuilder().nonNullable;
  1838. * let name = nnfb.control('Alex'); // FormControl<string>
  1839. * name.reset();
  1840. * console.log(name); // 'Alex'
  1841. * ```
  1842. *
  1843. * **Constructing non-nullable groups or arrays**
  1844. *
  1845. * When constructing a group or array, all automatically created inner controls will be
  1846. * non-nullable, and will reset to their initial values.
  1847. *
  1848. * ```ts
  1849. * let nnfb = new FormBuilder().nonNullable;
  1850. * let name = nnfb.group({who: 'Alex'}); // FormGroup<{who: FormControl<string>}>
  1851. * name.reset();
  1852. * console.log(name); // {who: 'Alex'}
  1853. * ```
  1854. * **Constructing *nullable* fields on groups or arrays**
  1855. *
  1856. * It is still possible to have a nullable field. In particular, any `FormControl` which is
  1857. * *already* constructed will not be altered. For example:
  1858. *
  1859. * ```ts
  1860. * let nnfb = new FormBuilder().nonNullable;
  1861. * // FormGroup<{who: FormControl<string|null>}>
  1862. * let name = nnfb.group({who: new FormControl('Alex')});
  1863. * name.reset(); console.log(name); // {who: null}
  1864. * ```
  1865. *
  1866. * Because the inner control is constructed explicitly by the caller, the builder has
  1867. * no control over how it is created, and cannot exclude the `null`.
  1868. */
  1869. get nonNullable(): NonNullableFormBuilder;
  1870. /**
  1871. * @description
  1872. * Constructs a new `FormGroup` instance. Accepts a single generic argument, which is an object
  1873. * containing all the keys and corresponding inner control types.
  1874. *
  1875. * @param controls A collection of child controls. The key for each child is the name
  1876. * under which it is registered.
  1877. *
  1878. * @param options Configuration options object for the `FormGroup`. The object should have the
  1879. * `AbstractControlOptions` type and might contain the following fields:
  1880. * * `validators`: A synchronous validator function, or an array of validator functions.
  1881. * * `asyncValidators`: A single async validator or array of async validator functions.
  1882. * * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur'
  1883. * | submit').
  1884. */
  1885. group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroup<{
  1886. [K in keyof T]: ɵElement<T[K], null>;
  1887. }>;
  1888. /**
  1889. * @description
  1890. * Constructs a new `FormGroup` instance.
  1891. *
  1892. * @deprecated This API is not typesafe and can result in issues with Closure Compiler renaming.
  1893. * Use the `FormBuilder#group` overload with `AbstractControlOptions` instead.
  1894. * Note that `AbstractControlOptions` expects `validators` and `asyncValidators` to be valid
  1895. * validators. If you have custom validators, make sure their validation function parameter is
  1896. * `AbstractControl` and not a sub-class, such as `FormGroup`. These functions will be called
  1897. * with an object of type `AbstractControl` and that cannot be automatically downcast to a
  1898. * subclass, so TypeScript sees this as an error. For example, change the `(group: FormGroup) =>
  1899. * ValidationErrors|null` signature to be `(group: AbstractControl) => ValidationErrors|null`.
  1900. *
  1901. * @param controls A record of child controls. The key for each child is the name
  1902. * under which the control is registered.
  1903. *
  1904. * @param options Configuration options object for the `FormGroup`. The legacy configuration
  1905. * object consists of:
  1906. * * `validator`: A synchronous validator function, or an array of validator functions.
  1907. * * `asyncValidator`: A single async validator or array of async validator functions
  1908. * Note: the legacy format is deprecated and might be removed in one of the next major versions
  1909. * of Angular.
  1910. */
  1911. group(controls: {
  1912. [key: string]: any;
  1913. }, options: {
  1914. [key: string]: any;
  1915. }): FormGroup;
  1916. /**
  1917. * @description
  1918. * Constructs a new `FormRecord` instance. Accepts a single generic argument, which is an object
  1919. * containing all the keys and corresponding inner control types.
  1920. *
  1921. * @param controls A collection of child controls. The key for each child is the name
  1922. * under which it is registered.
  1923. *
  1924. * @param options Configuration options object for the `FormRecord`. The object should have the
  1925. * `AbstractControlOptions` type and might contain the following fields:
  1926. * * `validators`: A synchronous validator function, or an array of validator functions.
  1927. * * `asyncValidators`: A single async validator or array of async validator functions.
  1928. * * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur'
  1929. * | submit').
  1930. */
  1931. record<T>(controls: {
  1932. [key: string]: T;
  1933. }, options?: AbstractControlOptions | null): FormRecord<ɵElement<T, null>>;
  1934. /** @deprecated Use `nonNullable` instead. */
  1935. control<T>(formState: T | FormControlState<T>, opts: FormControlOptions & {
  1936. initialValueIsDefault: true;
  1937. }): FormControl<T>;
  1938. control<T>(formState: T | FormControlState<T>, opts: FormControlOptions & {
  1939. nonNullable: true;
  1940. }): FormControl<T>;
  1941. /**
  1942. * @deprecated When passing an `options` argument, the `asyncValidator` argument has no effect.
  1943. */
  1944. control<T>(formState: T | FormControlState<T>, opts: FormControlOptions, asyncValidator: AsyncValidatorFn | AsyncValidatorFn[]): FormControl<T | null>;
  1945. control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T | null>;
  1946. /**
  1947. * Constructs a new `FormArray` from the given array of configurations,
  1948. * validators and options. Accepts a single generic argument, which is the type of each control
  1949. * inside the array.
  1950. *
  1951. * @param controls An array of child controls or control configs. Each child control is given an
  1952. * index when it is registered.
  1953. *
  1954. * @param validatorOrOpts A synchronous validator function, or an array of such functions, or an
  1955. * `AbstractControlOptions` object that contains
  1956. * validation functions and a validation trigger.
  1957. *
  1958. * @param asyncValidator A single async validator or array of async validator functions.
  1959. */
  1960. array<T>(controls: Array<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormArray<ɵElement<T, null>>;
  1961. static ɵfac: i0.ɵɵFactoryDeclaration<FormBuilder, never>;
  1962. static ɵprov: i0.ɵɵInjectableDeclaration<FormBuilder>;
  1963. }
  1964. /**
  1965. * Tracks the value and validation status of an individual form control.
  1966. *
  1967. * This is one of the four fundamental building blocks of Angular forms, along with
  1968. * `FormGroup`, `FormArray` and `FormRecord`. It extends the `AbstractControl` class that
  1969. * implements most of the base functionality for accessing the value, validation status,
  1970. * user interactions and events.
  1971. *
  1972. * `FormControl` takes a single generic argument, which describes the type of its value. This
  1973. * argument always implicitly includes `null` because the control can be reset. To change this
  1974. * behavior, set `nonNullable` or see the usage notes below.
  1975. *
  1976. * See [usage examples below](#usage-notes).
  1977. *
  1978. * @see `AbstractControl`
  1979. * @see [Reactive Forms Guide](guide/reactive-forms)
  1980. * @see [Usage Notes](#usage-notes)
  1981. *
  1982. * @publicApi
  1983. *
  1984. * @overriddenImplementation ɵFormControlCtor
  1985. *
  1986. * @usageNotes
  1987. *
  1988. * ### Initializing Form Controls
  1989. *
  1990. * Instantiate a `FormControl`, with an initial value.
  1991. *
  1992. * ```ts
  1993. * const control = new FormControl('some value');
  1994. * console.log(control.value); // 'some value'
  1995. * ```
  1996. *
  1997. * The following example initializes the control with a form state object. The `value`
  1998. * and `disabled` keys are required in this case.
  1999. *
  2000. * ```ts
  2001. * const control = new FormControl({ value: 'n/a', disabled: true });
  2002. * console.log(control.value); // 'n/a'
  2003. * console.log(control.status); // 'DISABLED'
  2004. * ```
  2005. *
  2006. * The following example initializes the control with a synchronous validator.
  2007. *
  2008. * ```ts
  2009. * const control = new FormControl('', Validators.required);
  2010. * console.log(control.value); // ''
  2011. * console.log(control.status); // 'INVALID'
  2012. * ```
  2013. *
  2014. * The following example initializes the control using an options object.
  2015. *
  2016. * ```ts
  2017. * const control = new FormControl('', {
  2018. * validators: Validators.required,
  2019. * asyncValidators: myAsyncValidator
  2020. * });
  2021. * ```
  2022. *
  2023. * ### The single type argument
  2024. *
  2025. * `FormControl` accepts a generic argument, which describes the type of its value.
  2026. * In most cases, this argument will be inferred.
  2027. *
  2028. * If you are initializing the control to `null`, or you otherwise wish to provide a
  2029. * wider type, you may specify the argument explicitly:
  2030. *
  2031. * ```
  2032. * let fc = new FormControl<string|null>(null);
  2033. * fc.setValue('foo');
  2034. * ```
  2035. *
  2036. * You might notice that `null` is always added to the type of the control.
  2037. * This is because the control will become `null` if you call `reset`. You can change
  2038. * this behavior by setting `{nonNullable: true}`.
  2039. *
  2040. * ### Configure the control to update on a blur event
  2041. *
  2042. * Set the `updateOn` option to `'blur'` to update on the blur `event`.
  2043. *
  2044. * ```ts
  2045. * const control = new FormControl('', { updateOn: 'blur' });
  2046. * ```
  2047. *
  2048. * ### Configure the control to update on a submit event
  2049. *
  2050. * Set the `updateOn` option to `'submit'` to update on a submit `event`.
  2051. *
  2052. * ```ts
  2053. * const control = new FormControl('', { updateOn: 'submit' });
  2054. * ```
  2055. *
  2056. * ### Reset the control back to a specific value
  2057. *
  2058. * You reset to a specific form state by passing through a standalone
  2059. * value or a form state object that contains both a value and a disabled state
  2060. * (these are the only two properties that cannot be calculated).
  2061. *
  2062. * ```ts
  2063. * const control = new FormControl('Nancy');
  2064. *
  2065. * console.log(control.value); // 'Nancy'
  2066. *
  2067. * control.reset('Drew');
  2068. *
  2069. * console.log(control.value); // 'Drew'
  2070. * ```
  2071. *
  2072. * ### Reset the control to its initial value
  2073. *
  2074. * If you wish to always reset the control to its initial value (instead of null),
  2075. * you can pass the `nonNullable` option:
  2076. *
  2077. * ```
  2078. * const control = new FormControl('Nancy', {nonNullable: true});
  2079. *
  2080. * console.log(control.value); // 'Nancy'
  2081. *
  2082. * control.reset();
  2083. *
  2084. * console.log(control.value); // 'Nancy'
  2085. * ```
  2086. *
  2087. * ### Reset the control back to an initial value and disabled
  2088. *
  2089. * ```
  2090. * const control = new FormControl('Nancy');
  2091. *
  2092. * console.log(control.value); // 'Nancy'
  2093. * console.log(control.status); // 'VALID'
  2094. *
  2095. * control.reset({ value: 'Drew', disabled: true });
  2096. *
  2097. * console.log(control.value); // 'Drew'
  2098. * console.log(control.status); // 'DISABLED'
  2099. * ```
  2100. */
  2101. export declare interface FormControl<TValue = any> extends AbstractControl<TValue> {
  2102. /**
  2103. * The default value of this FormControl, used whenever the control is reset without an explicit
  2104. * value. See {@link FormControlOptions#nonNullable} for more information on configuring
  2105. * a default value.
  2106. */
  2107. readonly defaultValue: TValue;
  2108. /**
  2109. * Sets a new value for the form control.
  2110. *
  2111. * @param value The new value for the control.
  2112. * @param options Configuration options that determine how the control propagates changes
  2113. * and emits events when the value changes.
  2114. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  2115. * updateValueAndValidity} method.
  2116. *
  2117. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  2118. * false.
  2119. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2120. * `valueChanges`
  2121. * observables emit events with the latest status and value when the control value is updated.
  2122. * When false, no events are emitted.
  2123. * * `emitModelToViewChange`: When true or not supplied (the default), each change triggers an
  2124. * `onChange` event to
  2125. * update the view.
  2126. * * `emitViewToModelChange`: When true or not supplied (the default), each change triggers an
  2127. * `ngModelChange`
  2128. * event to update the model.
  2129. *
  2130. */
  2131. setValue(value: TValue, options?: {
  2132. onlySelf?: boolean;
  2133. emitEvent?: boolean;
  2134. emitModelToViewChange?: boolean;
  2135. emitViewToModelChange?: boolean;
  2136. }): void;
  2137. /**
  2138. * Patches the value of a control.
  2139. *
  2140. * This function is functionally the same as {@link FormControl#setValue setValue} at this level.
  2141. * It exists for symmetry with {@link FormGroup#patchValue patchValue} on `FormGroups` and
  2142. * `FormArrays`, where it does behave differently.
  2143. *
  2144. * @see `setValue` for options
  2145. */
  2146. patchValue(value: TValue, options?: {
  2147. onlySelf?: boolean;
  2148. emitEvent?: boolean;
  2149. emitModelToViewChange?: boolean;
  2150. emitViewToModelChange?: boolean;
  2151. }): void;
  2152. /**
  2153. * Resets the form control, marking it `pristine` and `untouched`, and resetting
  2154. * the value. The new value will be the provided value (if passed), `null`, or the initial value
  2155. * if `nonNullable` was set in the constructor via {@link FormControlOptions}.
  2156. *
  2157. * ```ts
  2158. * // By default, the control will reset to null.
  2159. * const dog = new FormControl('spot');
  2160. * dog.reset(); // dog.value is null
  2161. *
  2162. * // If this flag is set, the control will instead reset to the initial value.
  2163. * const cat = new FormControl('tabby', {nonNullable: true});
  2164. * cat.reset(); // cat.value is "tabby"
  2165. *
  2166. * // A value passed to reset always takes precedence.
  2167. * const fish = new FormControl('finn', {nonNullable: true});
  2168. * fish.reset('bubble'); // fish.value is "bubble"
  2169. * ```
  2170. *
  2171. * @param formState Resets the control with an initial value,
  2172. * or an object that defines the initial value and disabled state.
  2173. *
  2174. * @param options Configuration options that determine how the control propagates changes
  2175. * and emits events after the value changes.
  2176. *
  2177. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  2178. * false.
  2179. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2180. * `valueChanges`
  2181. * observables emit events with the latest status and value when the control is reset.
  2182. * When false, no events are emitted.
  2183. *
  2184. */
  2185. reset(formState?: TValue | FormControlState<TValue>, options?: {
  2186. onlySelf?: boolean;
  2187. emitEvent?: boolean;
  2188. }): void;
  2189. /**
  2190. * For a simple FormControl, the raw value is equivalent to the value.
  2191. */
  2192. getRawValue(): TValue;
  2193. /**
  2194. * Register a listener for change events.
  2195. *
  2196. * @param fn The method that is called when the value changes
  2197. */
  2198. registerOnChange(fn: Function): void;
  2199. /**
  2200. * Register a listener for disabled events.
  2201. *
  2202. * @param fn The method that is called when the disabled status changes.
  2203. */
  2204. registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
  2205. }
  2206. export declare const FormControl: ɵFormControlCtor;
  2207. /**
  2208. * @description
  2209. * Synchronizes a standalone `FormControl` instance to a form control element.
  2210. *
  2211. * Note that support for using the `ngModel` input property and `ngModelChange` event with reactive
  2212. * form directives was deprecated in Angular v6 and is scheduled for removal in
  2213. * a future version of Angular.
  2214. * For details, see [Deprecated features](guide/deprecations#ngmodel-with-reactive-forms).
  2215. *
  2216. * @see [Reactive Forms Guide](guide/reactive-forms)
  2217. * @see `FormControl`
  2218. * @see `AbstractControl`
  2219. *
  2220. * @usageNotes
  2221. *
  2222. * The following example shows how to register a standalone control and set its value.
  2223. *
  2224. * {@example forms/ts/simpleFormControl/simple_form_control_example.ts region='Component'}
  2225. *
  2226. * @ngModule ReactiveFormsModule
  2227. * @publicApi
  2228. */
  2229. export declare class FormControlDirective extends NgControl implements OnChanges, OnDestroy {
  2230. private _ngModelWarningConfig;
  2231. private callSetDisabledState?;
  2232. /**
  2233. * Internal reference to the view model value.
  2234. * @nodoc
  2235. */
  2236. viewModel: any;
  2237. /**
  2238. * @description
  2239. * Tracks the `FormControl` instance bound to the directive.
  2240. */
  2241. form: FormControl;
  2242. /**
  2243. * @description
  2244. * Triggers a warning in dev mode that this input should not be used with reactive forms.
  2245. */
  2246. set isDisabled(isDisabled: boolean);
  2247. /** @deprecated as of v6 */
  2248. model: any;
  2249. /** @deprecated as of v6 */
  2250. update: EventEmitter<any>;
  2251. constructor(validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[], valueAccessors: ControlValueAccessor[], _ngModelWarningConfig: string | null, callSetDisabledState?: SetDisabledStateOption | undefined);
  2252. /** @nodoc */
  2253. ngOnChanges(changes: SimpleChanges): void;
  2254. /** @nodoc */
  2255. ngOnDestroy(): void;
  2256. /**
  2257. * @description
  2258. * Returns an array that represents the path from the top-level form to this control.
  2259. * Each index is the string name of the control on that level.
  2260. */
  2261. get path(): string[];
  2262. /**
  2263. * @description
  2264. * The `FormControl` bound to this directive.
  2265. */
  2266. get control(): FormControl;
  2267. /**
  2268. * @description
  2269. * Sets the new value for the view model and emits an `ngModelChange` event.
  2270. *
  2271. * @param newValue The new value for the view model.
  2272. */
  2273. viewToModelUpdate(newValue: any): void;
  2274. private _isControlChanged;
  2275. static ɵfac: i0.ɵɵFactoryDeclaration<FormControlDirective, [{ optional: true; self: true; }, { optional: true; self: true; }, { optional: true; self: true; }, { optional: true; }, { optional: true; }]>;
  2276. static ɵdir: i0.ɵɵDirectiveDeclaration<FormControlDirective, "[formControl]", ["ngForm"], { "form": { "alias": "formControl"; "required": false; }; "isDisabled": { "alias": "disabled"; "required": false; }; "model": { "alias": "ngModel"; "required": false; }; }, { "update": "ngModelChange"; }, never, never, false, never>;
  2277. }
  2278. /**
  2279. * @description
  2280. * Syncs a `FormControl` in an existing `FormGroup` to a form control
  2281. * element by name.
  2282. *
  2283. * @see [Reactive Forms Guide](guide/reactive-forms)
  2284. * @see `FormControl`
  2285. * @see `AbstractControl`
  2286. *
  2287. * @usageNotes
  2288. *
  2289. * ### Register `FormControl` within a group
  2290. *
  2291. * The following example shows how to register multiple form controls within a form group
  2292. * and set their value.
  2293. *
  2294. * {@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
  2295. *
  2296. * To see `formControlName` examples with different form control types, see:
  2297. *
  2298. * * Radio buttons: `RadioControlValueAccessor`
  2299. * * Selects: `SelectControlValueAccessor`
  2300. *
  2301. * ### Use with ngModel is deprecated
  2302. *
  2303. * Support for using the `ngModel` input property and `ngModelChange` event with reactive
  2304. * form directives has been deprecated in Angular v6 and is scheduled for removal in
  2305. * a future version of Angular.
  2306. *
  2307. * For details, see [Deprecated features](guide/deprecations#ngmodel-with-reactive-forms).
  2308. *
  2309. * @ngModule ReactiveFormsModule
  2310. * @publicApi
  2311. */
  2312. export declare class FormControlName extends NgControl implements OnChanges, OnDestroy {
  2313. private _ngModelWarningConfig;
  2314. private _added;
  2315. /**
  2316. * @description
  2317. * Tracks the `FormControl` instance bound to the directive.
  2318. */
  2319. readonly control: FormControl;
  2320. /**
  2321. * @description
  2322. * Tracks the name of the `FormControl` bound to the directive. The name corresponds
  2323. * to a key in the parent `FormGroup` or `FormArray`.
  2324. * Accepts a name as a string or a number.
  2325. * The name in the form of a string is useful for individual forms,
  2326. * while the numerical form allows for form controls to be bound
  2327. * to indices when iterating over controls in a `FormArray`.
  2328. */
  2329. name: string | number | null;
  2330. /**
  2331. * @description
  2332. * Triggers a warning in dev mode that this input should not be used with reactive forms.
  2333. */
  2334. set isDisabled(isDisabled: boolean);
  2335. /** @deprecated as of v6 */
  2336. model: any;
  2337. /** @deprecated as of v6 */
  2338. update: EventEmitter<any>;
  2339. constructor(parent: ControlContainer, validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[], valueAccessors: ControlValueAccessor[], _ngModelWarningConfig: string | null);
  2340. /** @nodoc */
  2341. ngOnChanges(changes: SimpleChanges): void;
  2342. /** @nodoc */
  2343. ngOnDestroy(): void;
  2344. /**
  2345. * @description
  2346. * Sets the new value for the view model and emits an `ngModelChange` event.
  2347. *
  2348. * @param newValue The new value for the view model.
  2349. */
  2350. viewToModelUpdate(newValue: any): void;
  2351. /**
  2352. * @description
  2353. * Returns an array that represents the path from the top-level form to this control.
  2354. * Each index is the string name of the control on that level.
  2355. */
  2356. get path(): string[];
  2357. /**
  2358. * @description
  2359. * The top-level directive for this group if present, otherwise null.
  2360. */
  2361. get formDirective(): any;
  2362. private _checkParentType;
  2363. private _setUpControl;
  2364. static ɵfac: i0.ɵɵFactoryDeclaration<FormControlName, [{ optional: true; host: true; skipSelf: true; }, { optional: true; self: true; }, { optional: true; self: true; }, { optional: true; self: true; }, { optional: true; }]>;
  2365. static ɵdir: i0.ɵɵDirectiveDeclaration<FormControlName, "[formControlName]", never, { "name": { "alias": "formControlName"; "required": false; }; "isDisabled": { "alias": "disabled"; "required": false; }; "model": { "alias": "ngModel"; "required": false; }; }, { "update": "ngModelChange"; }, never, never, false, never>;
  2366. }
  2367. /**
  2368. * Interface for options provided to a `FormControl`.
  2369. *
  2370. * This interface extends all options from {@link AbstractControlOptions}, plus some options
  2371. * unique to `FormControl`.
  2372. *
  2373. * @publicApi
  2374. */
  2375. export declare interface FormControlOptions extends AbstractControlOptions {
  2376. /**
  2377. * @description
  2378. * Whether to use the initial value used to construct the `FormControl` as its default value
  2379. * as well. If this option is false or not provided, the default value of a FormControl is `null`.
  2380. * When a FormControl is reset without an explicit value, its value reverts to
  2381. * its default value.
  2382. */
  2383. nonNullable?: boolean;
  2384. /**
  2385. * @deprecated Use `nonNullable` instead.
  2386. */
  2387. initialValueIsDefault?: boolean;
  2388. }
  2389. /**
  2390. * FormControlState is a boxed form value. It is an object with a `value` key and a `disabled` key.
  2391. *
  2392. * @publicApi
  2393. */
  2394. export declare interface FormControlState<T> {
  2395. value: T;
  2396. disabled: boolean;
  2397. }
  2398. /**
  2399. * A form can have several different statuses. Each
  2400. * possible status is returned as a string literal.
  2401. *
  2402. * * **VALID**: Reports that a control is valid, meaning that no errors exist in the input
  2403. * value.
  2404. * * **INVALID**: Reports that a control is invalid, meaning that an error exists in the input
  2405. * value.
  2406. * * **PENDING**: Reports that a control is pending, meaning that that async validation is
  2407. * occurring and errors are not yet available for the input value.
  2408. * * **DISABLED**: Reports that a control is
  2409. * disabled, meaning that the control is exempt from ancestor calculations of validity or value.
  2410. *
  2411. * @publicApi
  2412. */
  2413. export declare type FormControlStatus = 'VALID' | 'INVALID' | 'PENDING' | 'DISABLED';
  2414. /**
  2415. * Tracks the value and validity state of a group of `FormControl` instances.
  2416. *
  2417. * A `FormGroup` aggregates the values of each child `FormControl` into one object,
  2418. * with each control name as the key. It calculates its status by reducing the status values
  2419. * of its children. For example, if one of the controls in a group is invalid, the entire
  2420. * group becomes invalid.
  2421. *
  2422. * `FormGroup` is one of the four fundamental building blocks used to define forms in Angular,
  2423. * along with `FormControl`, `FormArray`, and `FormRecord`.
  2424. *
  2425. * When instantiating a `FormGroup`, pass in a collection of child controls as the first
  2426. * argument. The key for each child registers the name for the control.
  2427. *
  2428. * `FormGroup` is intended for use cases where the keys are known ahead of time.
  2429. * If you need to dynamically add and remove controls, use {@link FormRecord} instead.
  2430. *
  2431. * `FormGroup` accepts an optional type parameter `TControl`, which is an object type with inner
  2432. * control types as values.
  2433. *
  2434. * @usageNotes
  2435. *
  2436. * ### Create a form group with 2 controls
  2437. *
  2438. * ```
  2439. * const form = new FormGroup({
  2440. * first: new FormControl('Nancy', Validators.minLength(2)),
  2441. * last: new FormControl('Drew'),
  2442. * });
  2443. *
  2444. * console.log(form.value); // {first: 'Nancy', last; 'Drew'}
  2445. * console.log(form.status); // 'VALID'
  2446. * ```
  2447. *
  2448. * ### The type argument, and optional controls
  2449. *
  2450. * `FormGroup` accepts one generic argument, which is an object containing its inner controls.
  2451. * This type will usually be inferred automatically, but you can always specify it explicitly if you
  2452. * wish.
  2453. *
  2454. * If you have controls that are optional (i.e. they can be removed, you can use the `?` in the
  2455. * type):
  2456. *
  2457. * ```
  2458. * const form = new FormGroup<{
  2459. * first: FormControl<string|null>,
  2460. * middle?: FormControl<string|null>, // Middle name is optional.
  2461. * last: FormControl<string|null>,
  2462. * }>({
  2463. * first: new FormControl('Nancy'),
  2464. * last: new FormControl('Drew'),
  2465. * });
  2466. * ```
  2467. *
  2468. * ### Create a form group with a group-level validator
  2469. *
  2470. * You include group-level validators as the second arg, or group-level async
  2471. * validators as the third arg. These come in handy when you want to perform validation
  2472. * that considers the value of more than one child control.
  2473. *
  2474. * ```
  2475. * const form = new FormGroup({
  2476. * password: new FormControl('', Validators.minLength(2)),
  2477. * passwordConfirm: new FormControl('', Validators.minLength(2)),
  2478. * }, passwordMatchValidator);
  2479. *
  2480. *
  2481. * function passwordMatchValidator(g: FormGroup) {
  2482. * return g.get('password').value === g.get('passwordConfirm').value
  2483. * ? null : {'mismatch': true};
  2484. * }
  2485. * ```
  2486. *
  2487. * Like `FormControl` instances, you choose to pass in
  2488. * validators and async validators as part of an options object.
  2489. *
  2490. * ```
  2491. * const form = new FormGroup({
  2492. * password: new FormControl('')
  2493. * passwordConfirm: new FormControl('')
  2494. * }, { validators: passwordMatchValidator, asyncValidators: otherValidator });
  2495. * ```
  2496. *
  2497. * ### Set the updateOn property for all controls in a form group
  2498. *
  2499. * The options object is used to set a default value for each child
  2500. * control's `updateOn` property. If you set `updateOn` to `'blur'` at the
  2501. * group level, all child controls default to 'blur', unless the child
  2502. * has explicitly specified a different `updateOn` value.
  2503. *
  2504. * ```ts
  2505. * const c = new FormGroup({
  2506. * one: new FormControl()
  2507. * }, { updateOn: 'blur' });
  2508. * ```
  2509. *
  2510. * ### Using a FormGroup with optional controls
  2511. *
  2512. * It is possible to have optional controls in a FormGroup. An optional control can be removed later
  2513. * using `removeControl`, and can be omitted when calling `reset`. Optional controls must be
  2514. * declared optional in the group's type.
  2515. *
  2516. * ```ts
  2517. * const c = new FormGroup<{one?: FormControl<string>}>({
  2518. * one: new FormControl('')
  2519. * });
  2520. * ```
  2521. *
  2522. * Notice that `c.value.one` has type `string|null|undefined`. This is because calling `c.reset({})`
  2523. * without providing the optional key `one` will cause it to become `null`.
  2524. *
  2525. * @publicApi
  2526. */
  2527. export declare class FormGroup<TControl extends {
  2528. [K in keyof TControl]: AbstractControl<any>;
  2529. } = any> extends AbstractControl<ɵTypedOrUntyped<TControl, ɵFormGroupValue<TControl>, any>, ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any>> {
  2530. /**
  2531. * Creates a new `FormGroup` instance.
  2532. *
  2533. * @param controls A collection of child controls. The key for each child is the name
  2534. * under which it is registered.
  2535. *
  2536. * @param validatorOrOpts A synchronous validator function, or an array of
  2537. * such functions, or an `AbstractControlOptions` object that contains validation functions
  2538. * and a validation trigger.
  2539. *
  2540. * @param asyncValidator A single async validator or array of async validator functions
  2541. *
  2542. */
  2543. constructor(controls: TControl, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
  2544. controls: ɵTypedOrUntyped<TControl, TControl, {
  2545. [key: string]: AbstractControl<any>;
  2546. }>;
  2547. /**
  2548. * Registers a control with the group's list of controls. In a strongly-typed group, the control
  2549. * must be in the group's type (possibly as an optional key).
  2550. *
  2551. * This method does not update the value or validity of the control.
  2552. * Use {@link FormGroup#addControl addControl} instead.
  2553. *
  2554. * @param name The control name to register in the collection
  2555. * @param control Provides the control for the given name
  2556. */
  2557. registerControl<K extends string & keyof TControl>(name: K, control: TControl[K]): TControl[K];
  2558. registerControl(this: FormGroup<{
  2559. [key: string]: AbstractControl<any>;
  2560. }>, name: string, control: AbstractControl<any>): AbstractControl<any>;
  2561. /**
  2562. * Add a control to this group. In a strongly-typed group, the control must be in the group's type
  2563. * (possibly as an optional key).
  2564. *
  2565. * If a control with a given name already exists, it would *not* be replaced with a new one.
  2566. * If you want to replace an existing control, use the {@link FormGroup#setControl setControl}
  2567. * method instead. This method also updates the value and validity of the control.
  2568. *
  2569. * @param name The control name to add to the collection
  2570. * @param control Provides the control for the given name
  2571. * @param options Specifies whether this FormGroup instance should emit events after a new
  2572. * control is added.
  2573. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2574. * `valueChanges` observables emit events with the latest status and value when the control is
  2575. * added. When false, no events are emitted.
  2576. */
  2577. addControl(this: FormGroup<{
  2578. [key: string]: AbstractControl<any>;
  2579. }>, name: string, control: AbstractControl, options?: {
  2580. emitEvent?: boolean;
  2581. }): void;
  2582. addControl<K extends string & keyof TControl>(name: K, control: Required<TControl>[K], options?: {
  2583. emitEvent?: boolean;
  2584. }): void;
  2585. removeControl(this: FormGroup<{
  2586. [key: string]: AbstractControl<any>;
  2587. }>, name: string, options?: {
  2588. emitEvent?: boolean;
  2589. }): void;
  2590. removeControl<S extends string>(name: ɵOptionalKeys<TControl> & S, options?: {
  2591. emitEvent?: boolean;
  2592. }): void;
  2593. /**
  2594. * Replace an existing control. In a strongly-typed group, the control must be in the group's type
  2595. * (possibly as an optional key).
  2596. *
  2597. * If a control with a given name does not exist in this `FormGroup`, it will be added.
  2598. *
  2599. * @param name The control name to replace in the collection
  2600. * @param control Provides the control for the given name
  2601. * @param options Specifies whether this FormGroup instance should emit events after an
  2602. * existing control is replaced.
  2603. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2604. * `valueChanges` observables emit events with the latest status and value when the control is
  2605. * replaced with a new one. When false, no events are emitted.
  2606. */
  2607. setControl<K extends string & keyof TControl>(name: K, control: TControl[K], options?: {
  2608. emitEvent?: boolean;
  2609. }): void;
  2610. setControl(this: FormGroup<{
  2611. [key: string]: AbstractControl<any>;
  2612. }>, name: string, control: AbstractControl, options?: {
  2613. emitEvent?: boolean;
  2614. }): void;
  2615. /**
  2616. * Check whether there is an enabled control with the given name in the group.
  2617. *
  2618. * Reports false for disabled controls. If you'd like to check for existence in the group
  2619. * only, use {@link AbstractControl#get get} instead.
  2620. *
  2621. * @param controlName The control name to check for existence in the collection
  2622. *
  2623. * @returns false for disabled controls, true otherwise.
  2624. */
  2625. contains<K extends string>(controlName: K): boolean;
  2626. contains(this: FormGroup<{
  2627. [key: string]: AbstractControl<any>;
  2628. }>, controlName: string): boolean;
  2629. /**
  2630. * Sets the value of the `FormGroup`. It accepts an object that matches
  2631. * the structure of the group, with control names as keys.
  2632. *
  2633. * @usageNotes
  2634. * ### Set the complete value for the form group
  2635. *
  2636. * ```
  2637. * const form = new FormGroup({
  2638. * first: new FormControl(),
  2639. * last: new FormControl()
  2640. * });
  2641. *
  2642. * console.log(form.value); // {first: null, last: null}
  2643. *
  2644. * form.setValue({first: 'Nancy', last: 'Drew'});
  2645. * console.log(form.value); // {first: 'Nancy', last: 'Drew'}
  2646. * ```
  2647. *
  2648. * @throws When strict checks fail, such as setting the value of a control
  2649. * that doesn't exist or if you exclude a value of a control that does exist.
  2650. *
  2651. * @param value The new value for the control that matches the structure of the group.
  2652. * @param options Configuration options that determine how the control propagates changes
  2653. * and emits events after the value changes.
  2654. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  2655. * updateValueAndValidity} method.
  2656. *
  2657. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  2658. * false.
  2659. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2660. * `valueChanges`
  2661. * observables emit events with the latest status and value when the control value is updated.
  2662. * When false, no events are emitted.
  2663. */
  2664. setValue(value: ɵFormGroupRawValue<TControl>, options?: {
  2665. onlySelf?: boolean;
  2666. emitEvent?: boolean;
  2667. }): void;
  2668. /**
  2669. * Patches the value of the `FormGroup`. It accepts an object with control
  2670. * names as keys, and does its best to match the values to the correct controls
  2671. * in the group.
  2672. *
  2673. * It accepts both super-sets and sub-sets of the group without throwing an error.
  2674. *
  2675. * @usageNotes
  2676. * ### Patch the value for a form group
  2677. *
  2678. * ```
  2679. * const form = new FormGroup({
  2680. * first: new FormControl(),
  2681. * last: new FormControl()
  2682. * });
  2683. * console.log(form.value); // {first: null, last: null}
  2684. *
  2685. * form.patchValue({first: 'Nancy'});
  2686. * console.log(form.value); // {first: 'Nancy', last: null}
  2687. * ```
  2688. *
  2689. * @param value The object that matches the structure of the group.
  2690. * @param options Configuration options that determine how the control propagates changes and
  2691. * emits events after the value is patched.
  2692. * * `onlySelf`: When true, each change only affects this control and not its parent. Default is
  2693. * true.
  2694. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2695. * `valueChanges` observables emit events with the latest status and value when the control value
  2696. * is updated. When false, no events are emitted. The configuration options are passed to
  2697. * the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
  2698. */
  2699. patchValue(value: ɵFormGroupValue<TControl>, options?: {
  2700. onlySelf?: boolean;
  2701. emitEvent?: boolean;
  2702. }): void;
  2703. /**
  2704. * Resets the `FormGroup`, marks all descendants `pristine` and `untouched` and sets
  2705. * the value of all descendants to their default values, or null if no defaults were provided.
  2706. *
  2707. * You reset to a specific form state by passing in a map of states
  2708. * that matches the structure of your form, with control names as keys. The state
  2709. * is a standalone value or a form state object with both a value and a disabled
  2710. * status.
  2711. *
  2712. * @param value Resets the control with an initial value,
  2713. * or an object that defines the initial value and disabled state.
  2714. *
  2715. * @param options Configuration options that determine how the control propagates changes
  2716. * and emits events when the group is reset.
  2717. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  2718. * false.
  2719. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2720. * `valueChanges`
  2721. * observables emit events with the latest status and value when the control is reset.
  2722. * When false, no events are emitted.
  2723. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  2724. * updateValueAndValidity} method.
  2725. *
  2726. * @usageNotes
  2727. *
  2728. * ### Reset the form group values
  2729. *
  2730. * ```ts
  2731. * const form = new FormGroup({
  2732. * first: new FormControl('first name'),
  2733. * last: new FormControl('last name')
  2734. * });
  2735. *
  2736. * console.log(form.value); // {first: 'first name', last: 'last name'}
  2737. *
  2738. * form.reset({ first: 'name', last: 'last name' });
  2739. *
  2740. * console.log(form.value); // {first: 'name', last: 'last name'}
  2741. * ```
  2742. *
  2743. * ### Reset the form group values and disabled status
  2744. *
  2745. * ```
  2746. * const form = new FormGroup({
  2747. * first: new FormControl('first name'),
  2748. * last: new FormControl('last name')
  2749. * });
  2750. *
  2751. * form.reset({
  2752. * first: {value: 'name', disabled: true},
  2753. * last: 'last'
  2754. * });
  2755. *
  2756. * console.log(form.value); // {last: 'last'}
  2757. * console.log(form.get('first').status); // 'DISABLED'
  2758. * ```
  2759. */
  2760. reset(value?: ɵTypedOrUntyped<TControl, ɵFormGroupValue<TControl>, any>, options?: {
  2761. onlySelf?: boolean;
  2762. emitEvent?: boolean;
  2763. }): void;
  2764. /**
  2765. * The aggregate value of the `FormGroup`, including any disabled controls.
  2766. *
  2767. * Retrieves all values regardless of disabled status.
  2768. */
  2769. getRawValue(): ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any>;
  2770. }
  2771. /**
  2772. * @description
  2773. *
  2774. * Binds an existing `FormGroup` or `FormRecord` to a DOM element.
  2775. *
  2776. * This directive accepts an existing `FormGroup` instance. It will then use this
  2777. * `FormGroup` instance to match any child `FormControl`, `FormGroup`/`FormRecord`,
  2778. * and `FormArray` instances to child `FormControlName`, `FormGroupName`,
  2779. * and `FormArrayName` directives.
  2780. *
  2781. * @see [Reactive Forms Guide](guide/reactive-forms)
  2782. * @see `AbstractControl`
  2783. *
  2784. * @usageNotes
  2785. * ### Register Form Group
  2786. *
  2787. * The following example registers a `FormGroup` with first name and last name controls,
  2788. * and listens for the *ngSubmit* event when the button is clicked.
  2789. *
  2790. * {@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
  2791. *
  2792. * @ngModule ReactiveFormsModule
  2793. * @publicApi
  2794. */
  2795. export declare class FormGroupDirective extends ControlContainer implements Form, OnChanges, OnDestroy {
  2796. private callSetDisabledState?;
  2797. /**
  2798. * @description
  2799. * Reports whether the form submission has been triggered.
  2800. */
  2801. readonly submitted: boolean;
  2802. /**
  2803. * Reference to an old form group input value, which is needed to cleanup old instance in case it
  2804. * was replaced with a new one.
  2805. */
  2806. private _oldForm;
  2807. /**
  2808. * Callback that should be invoked when controls in FormGroup or FormArray collection change
  2809. * (added or removed). This callback triggers corresponding DOM updates.
  2810. */
  2811. private readonly _onCollectionChange;
  2812. /**
  2813. * @description
  2814. * Tracks the list of added `FormControlName` instances
  2815. */
  2816. directives: FormControlName[];
  2817. /**
  2818. * @description
  2819. * Tracks the `FormGroup` bound to this directive.
  2820. */
  2821. form: FormGroup;
  2822. /**
  2823. * @description
  2824. * Emits an event when the form submission has been triggered.
  2825. */
  2826. ngSubmit: EventEmitter<any>;
  2827. constructor(validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[], callSetDisabledState?: SetDisabledStateOption | undefined);
  2828. /** @nodoc */
  2829. ngOnChanges(changes: SimpleChanges): void;
  2830. /** @nodoc */
  2831. ngOnDestroy(): void;
  2832. /**
  2833. * @description
  2834. * Returns this directive's instance.
  2835. */
  2836. get formDirective(): Form;
  2837. /**
  2838. * @description
  2839. * Returns the `FormGroup` bound to this directive.
  2840. */
  2841. get control(): FormGroup;
  2842. /**
  2843. * @description
  2844. * Returns an array representing the path to this group. Because this directive
  2845. * always lives at the top level of a form, it always an empty array.
  2846. */
  2847. get path(): string[];
  2848. /**
  2849. * @description
  2850. * Method that sets up the control directive in this group, re-calculates its value
  2851. * and validity, and adds the instance to the internal list of directives.
  2852. *
  2853. * @param dir The `FormControlName` directive instance.
  2854. */
  2855. addControl(dir: FormControlName): FormControl;
  2856. /**
  2857. * @description
  2858. * Retrieves the `FormControl` instance from the provided `FormControlName` directive
  2859. *
  2860. * @param dir The `FormControlName` directive instance.
  2861. */
  2862. getControl(dir: FormControlName): FormControl;
  2863. /**
  2864. * @description
  2865. * Removes the `FormControlName` instance from the internal list of directives
  2866. *
  2867. * @param dir The `FormControlName` directive instance.
  2868. */
  2869. removeControl(dir: FormControlName): void;
  2870. /**
  2871. * Adds a new `FormGroupName` directive instance to the form.
  2872. *
  2873. * @param dir The `FormGroupName` directive instance.
  2874. */
  2875. addFormGroup(dir: FormGroupName): void;
  2876. /**
  2877. * Performs the necessary cleanup when a `FormGroupName` directive instance is removed from the
  2878. * view.
  2879. *
  2880. * @param dir The `FormGroupName` directive instance.
  2881. */
  2882. removeFormGroup(dir: FormGroupName): void;
  2883. /**
  2884. * @description
  2885. * Retrieves the `FormGroup` for a provided `FormGroupName` directive instance
  2886. *
  2887. * @param dir The `FormGroupName` directive instance.
  2888. */
  2889. getFormGroup(dir: FormGroupName): FormGroup;
  2890. /**
  2891. * Performs the necessary setup when a `FormArrayName` directive instance is added to the view.
  2892. *
  2893. * @param dir The `FormArrayName` directive instance.
  2894. */
  2895. addFormArray(dir: FormArrayName): void;
  2896. /**
  2897. * Performs the necessary cleanup when a `FormArrayName` directive instance is removed from the
  2898. * view.
  2899. *
  2900. * @param dir The `FormArrayName` directive instance.
  2901. */
  2902. removeFormArray(dir: FormArrayName): void;
  2903. /**
  2904. * @description
  2905. * Retrieves the `FormArray` for a provided `FormArrayName` directive instance.
  2906. *
  2907. * @param dir The `FormArrayName` directive instance.
  2908. */
  2909. getFormArray(dir: FormArrayName): FormArray;
  2910. /**
  2911. * Sets the new value for the provided `FormControlName` directive.
  2912. *
  2913. * @param dir The `FormControlName` directive instance.
  2914. * @param value The new value for the directive's control.
  2915. */
  2916. updateModel(dir: FormControlName, value: any): void;
  2917. /**
  2918. * @description
  2919. * Method called with the "submit" event is triggered on the form.
  2920. * Triggers the `ngSubmit` emitter to emit the "submit" event as its payload.
  2921. *
  2922. * @param $event The "submit" event object
  2923. */
  2924. onSubmit($event: Event): boolean;
  2925. /**
  2926. * @description
  2927. * Method called when the "reset" event is triggered on the form.
  2928. */
  2929. onReset(): void;
  2930. /**
  2931. * @description
  2932. * Resets the form to an initial value and resets its submitted status.
  2933. *
  2934. * @param value The new value for the form.
  2935. */
  2936. resetForm(value?: any): void;
  2937. private _setUpFormContainer;
  2938. private _cleanUpFormContainer;
  2939. private _updateRegistrations;
  2940. private _updateValidators;
  2941. private _checkFormPresent;
  2942. static ɵfac: i0.ɵɵFactoryDeclaration<FormGroupDirective, [{ optional: true; self: true; }, { optional: true; self: true; }, { optional: true; }]>;
  2943. static ɵdir: i0.ɵɵDirectiveDeclaration<FormGroupDirective, "[formGroup]", ["ngForm"], { "form": { "alias": "formGroup"; "required": false; }; }, { "ngSubmit": "ngSubmit"; }, never, never, false, never>;
  2944. }
  2945. /**
  2946. * @description
  2947. *
  2948. * Syncs a nested `FormGroup` or `FormRecord` to a DOM element.
  2949. *
  2950. * This directive can only be used with a parent `FormGroupDirective`.
  2951. *
  2952. * It accepts the string name of the nested `FormGroup` or `FormRecord` to link, and
  2953. * looks for a `FormGroup` or `FormRecord` registered with that name in the parent
  2954. * `FormGroup` instance you passed into `FormGroupDirective`.
  2955. *
  2956. * Use nested form groups to validate a sub-group of a
  2957. * form separately from the rest or to group the values of certain
  2958. * controls into their own nested object.
  2959. *
  2960. * @see [Reactive Forms Guide](guide/reactive-forms)
  2961. *
  2962. * @usageNotes
  2963. *
  2964. * ### Access the group by name
  2965. *
  2966. * The following example uses the `AbstractControl.get` method to access the
  2967. * associated `FormGroup`
  2968. *
  2969. * ```ts
  2970. * this.form.get('name');
  2971. * ```
  2972. *
  2973. * ### Access individual controls in the group
  2974. *
  2975. * The following example uses the `AbstractControl.get` method to access
  2976. * individual controls within the group using dot syntax.
  2977. *
  2978. * ```ts
  2979. * this.form.get('name.first');
  2980. * ```
  2981. *
  2982. * ### Register a nested `FormGroup`.
  2983. *
  2984. * The following example registers a nested *name* `FormGroup` within an existing `FormGroup`,
  2985. * and provides methods to retrieve the nested `FormGroup` and individual controls.
  2986. *
  2987. * {@example forms/ts/nestedFormGroup/nested_form_group_example.ts region='Component'}
  2988. *
  2989. * @ngModule ReactiveFormsModule
  2990. * @publicApi
  2991. */
  2992. export declare class FormGroupName extends AbstractFormGroupDirective implements OnInit, OnDestroy {
  2993. /**
  2994. * @description
  2995. * Tracks the name of the `FormGroup` bound to the directive. The name corresponds
  2996. * to a key in the parent `FormGroup` or `FormArray`.
  2997. * Accepts a name as a string or a number.
  2998. * The name in the form of a string is useful for individual forms,
  2999. * while the numerical form allows for form groups to be bound
  3000. * to indices when iterating over groups in a `FormArray`.
  3001. */
  3002. name: string | number | null;
  3003. constructor(parent: ControlContainer, validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[]);
  3004. static ɵfac: i0.ɵɵFactoryDeclaration<FormGroupName, [{ optional: true; host: true; skipSelf: true; }, { optional: true; self: true; }, { optional: true; self: true; }]>;
  3005. static ɵdir: i0.ɵɵDirectiveDeclaration<FormGroupName, "[formGroupName]", never, { "name": { "alias": "formGroupName"; "required": false; }; }, {}, never, never, false, never>;
  3006. }
  3007. declare type FormHooks = 'change' | 'blur' | 'submit';
  3008. /**
  3009. * Tracks the value and validity state of a collection of `FormControl` instances, each of which has
  3010. * the same value type.
  3011. *
  3012. * `FormRecord` is very similar to {@link FormGroup}, except it can be used with a dynamic keys,
  3013. * with controls added and removed as needed.
  3014. *
  3015. * `FormRecord` accepts one generic argument, which describes the type of the controls it contains.
  3016. *
  3017. * @usageNotes
  3018. *
  3019. * ```
  3020. * let numbers = new FormRecord({bill: new FormControl('415-123-456')});
  3021. * numbers.addControl('bob', new FormControl('415-234-567'));
  3022. * numbers.removeControl('bill');
  3023. * ```
  3024. *
  3025. * @publicApi
  3026. */
  3027. export declare class FormRecord<TControl extends AbstractControl = AbstractControl> extends FormGroup<{
  3028. [key: string]: TControl;
  3029. }> {
  3030. }
  3031. export declare interface FormRecord<TControl> {
  3032. /**
  3033. * Registers a control with the records's list of controls.
  3034. *
  3035. * See `FormGroup#registerControl` for additional information.
  3036. */
  3037. registerControl(name: string, control: TControl): TControl;
  3038. /**
  3039. * Add a control to this group.
  3040. *
  3041. * See `FormGroup#addControl` for additional information.
  3042. */
  3043. addControl(name: string, control: TControl, options?: {
  3044. emitEvent?: boolean;
  3045. }): void;
  3046. /**
  3047. * Remove a control from this group.
  3048. *
  3049. * See `FormGroup#removeControl` for additional information.
  3050. */
  3051. removeControl(name: string, options?: {
  3052. emitEvent?: boolean;
  3053. }): void;
  3054. /**
  3055. * Replace an existing control.
  3056. *
  3057. * See `FormGroup#setControl` for additional information.
  3058. */
  3059. setControl(name: string, control: TControl, options?: {
  3060. emitEvent?: boolean;
  3061. }): void;
  3062. /**
  3063. * Check whether there is an enabled control with the given name in the group.
  3064. *
  3065. * See `FormGroup#contains` for additional information.
  3066. */
  3067. contains(controlName: string): boolean;
  3068. /**
  3069. * Sets the value of the `FormRecord`. It accepts an object that matches
  3070. * the structure of the group, with control names as keys.
  3071. *
  3072. * See `FormGroup#setValue` for additional information.
  3073. */
  3074. setValue(value: {
  3075. [key: string]: ɵValue<TControl>;
  3076. }, options?: {
  3077. onlySelf?: boolean;
  3078. emitEvent?: boolean;
  3079. }): void;
  3080. /**
  3081. * Patches the value of the `FormRecord`. It accepts an object with control
  3082. * names as keys, and does its best to match the values to the correct controls
  3083. * in the group.
  3084. *
  3085. * See `FormGroup#patchValue` for additional information.
  3086. */
  3087. patchValue(value: {
  3088. [key: string]: ɵValue<TControl>;
  3089. }, options?: {
  3090. onlySelf?: boolean;
  3091. emitEvent?: boolean;
  3092. }): void;
  3093. /**
  3094. * Resets the `FormRecord`, marks all descendants `pristine` and `untouched` and sets
  3095. * the value of all descendants to null.
  3096. *
  3097. * See `FormGroup#reset` for additional information.
  3098. */
  3099. reset(value?: {
  3100. [key: string]: ɵValue<TControl>;
  3101. }, options?: {
  3102. onlySelf?: boolean;
  3103. emitEvent?: boolean;
  3104. }): void;
  3105. /**
  3106. * The aggregate value of the `FormRecord`, including any disabled controls.
  3107. *
  3108. * See `FormGroup#getRawValue` for additional information.
  3109. */
  3110. getRawValue(): {
  3111. [key: string]: ɵRawValue<TControl>;
  3112. };
  3113. }
  3114. /**
  3115. * Exports the required providers and directives for template-driven forms,
  3116. * making them available for import by NgModules that import this module.
  3117. *
  3118. * Providers associated with this module:
  3119. * * `RadioControlRegistry`
  3120. *
  3121. * @see [Forms Overview](/guide/forms-overview)
  3122. * @see [Template-driven Forms Guide](/guide/forms)
  3123. *
  3124. * @publicApi
  3125. */
  3126. export declare class FormsModule {
  3127. /**
  3128. * @description
  3129. * Provides options for configuring the forms module.
  3130. *
  3131. * @param opts An object of configuration options
  3132. * * `callSetDisabledState` Configures whether to `always` call `setDisabledState`, which is more
  3133. * correct, or to only call it `whenDisabled`, which is the legacy behavior.
  3134. */
  3135. static withConfig(opts: {
  3136. callSetDisabledState?: SetDisabledStateOption;
  3137. }): ModuleWithProviders<FormsModule>;
  3138. static ɵfac: i0.ɵɵFactoryDeclaration<FormsModule, never>;
  3139. static ɵmod: i0.ɵɵNgModuleDeclaration<FormsModule, [typeof i1_2.NgModel, typeof i2_2.NgModelGroup, typeof i3_2.NgForm], never, [typeof i4_2.ɵInternalFormsSharedModule, typeof i1_2.NgModel, typeof i2_2.NgModelGroup, typeof i3_2.NgForm]>;
  3140. static ɵinj: i0.ɵɵInjectorDeclaration<FormsModule>;
  3141. }
  3142. declare namespace i1 {
  3143. export {
  3144. ɵNgNoValidate,
  3145. ɵNgNoValidate as NgNoValidate
  3146. }
  3147. }
  3148. declare namespace i10 {
  3149. export {
  3150. ValidationErrors,
  3151. Validator,
  3152. MAX_VALIDATOR,
  3153. MaxValidator,
  3154. MIN_VALIDATOR,
  3155. MinValidator,
  3156. AsyncValidator,
  3157. REQUIRED_VALIDATOR,
  3158. CHECKBOX_REQUIRED_VALIDATOR,
  3159. RequiredValidator,
  3160. CheckboxRequiredValidator,
  3161. EMAIL_VALIDATOR,
  3162. EmailValidator,
  3163. ValidatorFn,
  3164. AsyncValidatorFn,
  3165. MIN_LENGTH_VALIDATOR,
  3166. MinLengthValidator,
  3167. MAX_LENGTH_VALIDATOR,
  3168. MaxLengthValidator,
  3169. PATTERN_VALIDATOR,
  3170. PatternValidator
  3171. }
  3172. }
  3173. declare namespace i1_2 {
  3174. export {
  3175. NgModel
  3176. }
  3177. }
  3178. declare namespace i2 {
  3179. export {
  3180. SelectControlValueAccessor,
  3181. NgSelectOption
  3182. }
  3183. }
  3184. declare namespace i2_2 {
  3185. export {
  3186. modelGroupProvider,
  3187. NgModelGroup
  3188. }
  3189. }
  3190. declare namespace i3 {
  3191. export {
  3192. SelectMultipleControlValueAccessor,
  3193. ɵNgSelectMultipleOption,
  3194. ɵNgSelectMultipleOption as NgSelectMultipleOption
  3195. }
  3196. }
  3197. declare namespace i3_2 {
  3198. export {
  3199. NgForm
  3200. }
  3201. }
  3202. declare namespace i4 {
  3203. export {
  3204. DEFAULT_VALUE_ACCESSOR,
  3205. COMPOSITION_BUFFER_MODE,
  3206. DefaultValueAccessor
  3207. }
  3208. }
  3209. declare namespace i4_2 {
  3210. export {
  3211. CheckboxControlValueAccessor,
  3212. ControlValueAccessor,
  3213. DefaultValueAccessor,
  3214. NgControl,
  3215. NgControlStatus,
  3216. NgControlStatusGroup,
  3217. NgForm,
  3218. NgModel,
  3219. NgModelGroup,
  3220. NumberValueAccessor,
  3221. RadioControlValueAccessor,
  3222. RangeValueAccessor,
  3223. FormControlDirective,
  3224. NG_MODEL_WITH_FORM_CONTROL_WARNING,
  3225. FormControlName,
  3226. FormGroupDirective,
  3227. FormArrayName,
  3228. FormGroupName,
  3229. NgSelectOption,
  3230. SelectControlValueAccessor,
  3231. ɵNgSelectMultipleOption as NgSelectMultipleOption,
  3232. SelectMultipleControlValueAccessor,
  3233. CALL_SET_DISABLED_STATE,
  3234. SHARED_FORM_DIRECTIVES,
  3235. TEMPLATE_DRIVEN_DIRECTIVES,
  3236. REACTIVE_DRIVEN_DIRECTIVES,
  3237. ɵInternalFormsSharedModule,
  3238. ɵInternalFormsSharedModule as InternalFormsSharedModule
  3239. }
  3240. }
  3241. declare namespace i5 {
  3242. export {
  3243. NumberValueAccessor
  3244. }
  3245. }
  3246. declare namespace i5_2 {
  3247. export {
  3248. NG_MODEL_WITH_FORM_CONTROL_WARNING,
  3249. FormControlDirective
  3250. }
  3251. }
  3252. declare namespace i6 {
  3253. export {
  3254. RangeValueAccessor
  3255. }
  3256. }
  3257. declare namespace i6_2 {
  3258. export {
  3259. FormGroupDirective
  3260. }
  3261. }
  3262. declare namespace i7 {
  3263. export {
  3264. CheckboxControlValueAccessor
  3265. }
  3266. }
  3267. declare namespace i7_2 {
  3268. export {
  3269. FormControlName
  3270. }
  3271. }
  3272. declare namespace i8 {
  3273. export {
  3274. RadioControlRegistryModule,
  3275. RadioControlRegistry,
  3276. RadioControlValueAccessor
  3277. }
  3278. }
  3279. declare namespace i8_2 {
  3280. export {
  3281. FormGroupName,
  3282. formArrayNameProvider,
  3283. FormArrayName
  3284. }
  3285. }
  3286. declare namespace i9 {
  3287. export {
  3288. AbstractControlStatus,
  3289. ngControlStatusHost,
  3290. ngGroupStatusHost,
  3291. NgControlStatus,
  3292. NgControlStatusGroup
  3293. }
  3294. }
  3295. /**
  3296. * @description
  3297. * Asserts that the given control is an instance of `FormArray`
  3298. *
  3299. * @publicApi
  3300. */
  3301. export declare const isFormArray: (control: unknown) => control is FormArray<any>;
  3302. /**
  3303. * @description
  3304. * Asserts that the given control is an instance of `FormControl`
  3305. *
  3306. * @publicApi
  3307. */
  3308. export declare const isFormControl: (control: unknown) => control is FormControl<any>;
  3309. /**
  3310. * @description
  3311. * Asserts that the given control is an instance of `FormGroup`
  3312. *
  3313. * @publicApi
  3314. */
  3315. export declare const isFormGroup: (control: unknown) => control is FormGroup<any>;
  3316. /**
  3317. * @description
  3318. * Asserts that the given control is an instance of `FormRecord`
  3319. *
  3320. * @publicApi
  3321. */
  3322. export declare const isFormRecord: (control: unknown) => control is FormRecord<AbstractControl<any, any>>;
  3323. /**
  3324. * @description
  3325. * Provider which adds `MaxLengthValidator` to the `NG_VALIDATORS` multi-provider list.
  3326. */
  3327. declare const MAX_LENGTH_VALIDATOR: any;
  3328. /**
  3329. * @description
  3330. * Provider which adds `MaxValidator` to the `NG_VALIDATORS` multi-provider list.
  3331. */
  3332. declare const MAX_VALIDATOR: Provider;
  3333. /**
  3334. * A directive that adds max length validation to controls marked with the
  3335. * `maxlength` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  3336. *
  3337. * @see [Form Validation](guide/form-validation)
  3338. *
  3339. * @usageNotes
  3340. *
  3341. * ### Adding a maximum length validator
  3342. *
  3343. * The following example shows how to add a maximum length validator to an input attached to an
  3344. * ngModel binding.
  3345. *
  3346. * ```html
  3347. * <input name="firstName" ngModel maxlength="25">
  3348. * ```
  3349. *
  3350. * @ngModule ReactiveFormsModule
  3351. * @ngModule FormsModule
  3352. * @publicApi
  3353. */
  3354. export declare class MaxLengthValidator extends AbstractValidatorDirective {
  3355. /**
  3356. * @description
  3357. * Tracks changes to the minimum length bound to this directive.
  3358. */
  3359. maxlength: string | number | null;
  3360. static ɵfac: i0.ɵɵFactoryDeclaration<MaxLengthValidator, never>;
  3361. static ɵdir: i0.ɵɵDirectiveDeclaration<MaxLengthValidator, "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", never, { "maxlength": { "alias": "maxlength"; "required": false; }; }, {}, never, never, false, never>;
  3362. }
  3363. /**
  3364. * A directive which installs the {@link MaxValidator} for any `formControlName`,
  3365. * `formControl`, or control with `ngModel` that also has a `max` attribute.
  3366. *
  3367. * @see [Form Validation](guide/form-validation)
  3368. *
  3369. * @usageNotes
  3370. *
  3371. * ### Adding a max validator
  3372. *
  3373. * The following example shows how to add a max validator to an input attached to an
  3374. * ngModel binding.
  3375. *
  3376. * ```html
  3377. * <input type="number" ngModel max="4">
  3378. * ```
  3379. *
  3380. * @ngModule ReactiveFormsModule
  3381. * @ngModule FormsModule
  3382. * @publicApi
  3383. */
  3384. export declare class MaxValidator extends AbstractValidatorDirective {
  3385. /**
  3386. * @description
  3387. * Tracks changes to the max bound to this directive.
  3388. */
  3389. max: string | number | null;
  3390. static ɵfac: i0.ɵɵFactoryDeclaration<MaxValidator, never>;
  3391. static ɵdir: i0.ɵɵDirectiveDeclaration<MaxValidator, "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", never, { "max": { "alias": "max"; "required": false; }; }, {}, never, never, false, never>;
  3392. }
  3393. /**
  3394. * @description
  3395. * Provider which adds `MinLengthValidator` to the `NG_VALIDATORS` multi-provider list.
  3396. */
  3397. declare const MIN_LENGTH_VALIDATOR: any;
  3398. /**
  3399. * @description
  3400. * Provider which adds `MinValidator` to the `NG_VALIDATORS` multi-provider list.
  3401. */
  3402. declare const MIN_VALIDATOR: Provider;
  3403. /**
  3404. * A directive that adds minimum length validation to controls marked with the
  3405. * `minlength` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  3406. *
  3407. * @see [Form Validation](guide/form-validation)
  3408. *
  3409. * @usageNotes
  3410. *
  3411. * ### Adding a minimum length validator
  3412. *
  3413. * The following example shows how to add a minimum length validator to an input attached to an
  3414. * ngModel binding.
  3415. *
  3416. * ```html
  3417. * <input name="firstName" ngModel minlength="4">
  3418. * ```
  3419. *
  3420. * @ngModule ReactiveFormsModule
  3421. * @ngModule FormsModule
  3422. * @publicApi
  3423. */
  3424. export declare class MinLengthValidator extends AbstractValidatorDirective {
  3425. /**
  3426. * @description
  3427. * Tracks changes to the minimum length bound to this directive.
  3428. */
  3429. minlength: string | number | null;
  3430. static ɵfac: i0.ɵɵFactoryDeclaration<MinLengthValidator, never>;
  3431. static ɵdir: i0.ɵɵDirectiveDeclaration<MinLengthValidator, "[minlength][formControlName],[minlength][formControl],[minlength][ngModel]", never, { "minlength": { "alias": "minlength"; "required": false; }; }, {}, never, never, false, never>;
  3432. }
  3433. /**
  3434. * A directive which installs the {@link MinValidator} for any `formControlName`,
  3435. * `formControl`, or control with `ngModel` that also has a `min` attribute.
  3436. *
  3437. * @see [Form Validation](guide/form-validation)
  3438. *
  3439. * @usageNotes
  3440. *
  3441. * ### Adding a min validator
  3442. *
  3443. * The following example shows how to add a min validator to an input attached to an
  3444. * ngModel binding.
  3445. *
  3446. * ```html
  3447. * <input type="number" ngModel min="4">
  3448. * ```
  3449. *
  3450. * @ngModule ReactiveFormsModule
  3451. * @ngModule FormsModule
  3452. * @publicApi
  3453. */
  3454. export declare class MinValidator extends AbstractValidatorDirective {
  3455. /**
  3456. * @description
  3457. * Tracks changes to the min bound to this directive.
  3458. */
  3459. min: string | number | null;
  3460. static ɵfac: i0.ɵɵFactoryDeclaration<MinValidator, never>;
  3461. static ɵdir: i0.ɵɵDirectiveDeclaration<MinValidator, "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", never, { "min": { "alias": "min"; "required": false; }; }, {}, never, never, false, never>;
  3462. }
  3463. declare const modelGroupProvider: any;
  3464. /**
  3465. * @description
  3466. * An `InjectionToken` for registering additional asynchronous validators used with
  3467. * `AbstractControl`s.
  3468. *
  3469. * @see `NG_VALIDATORS`
  3470. *
  3471. * @usageNotes
  3472. *
  3473. * ### Provide a custom async validator directive
  3474. *
  3475. * The following example implements the `AsyncValidator` interface to create an
  3476. * async validator directive with a custom error key.
  3477. *
  3478. * ```typescript
  3479. * @Directive({
  3480. * selector: '[customAsyncValidator]',
  3481. * providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi:
  3482. * true}]
  3483. * })
  3484. * class CustomAsyncValidatorDirective implements AsyncValidator {
  3485. * validate(control: AbstractControl): Promise<ValidationErrors|null> {
  3486. * return Promise.resolve({'custom': true});
  3487. * }
  3488. * }
  3489. * ```
  3490. *
  3491. * @publicApi
  3492. */
  3493. export declare const NG_ASYNC_VALIDATORS: InjectionToken<(Function | Validator)[]>;
  3494. /**
  3495. * Token to provide to turn off the ngModel warning on formControl and formControlName.
  3496. */
  3497. declare const NG_MODEL_WITH_FORM_CONTROL_WARNING: InjectionToken<unknown>;
  3498. /**
  3499. * @description
  3500. * An `InjectionToken` for registering additional synchronous validators used with
  3501. * `AbstractControl`s.
  3502. *
  3503. * @see `NG_ASYNC_VALIDATORS`
  3504. *
  3505. * @usageNotes
  3506. *
  3507. * ### Providing a custom validator
  3508. *
  3509. * The following example registers a custom validator directive. Adding the validator to the
  3510. * existing collection of validators requires the `multi: true` option.
  3511. *
  3512. * ```typescript
  3513. * @Directive({
  3514. * selector: '[customValidator]',
  3515. * providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
  3516. * })
  3517. * class CustomValidatorDirective implements Validator {
  3518. * validate(control: AbstractControl): ValidationErrors | null {
  3519. * return { 'custom': true };
  3520. * }
  3521. * }
  3522. * ```
  3523. *
  3524. * @publicApi
  3525. */
  3526. export declare const NG_VALIDATORS: InjectionToken<(Function | Validator)[]>;
  3527. /**
  3528. * Used to provide a `ControlValueAccessor` for form controls.
  3529. *
  3530. * See `DefaultValueAccessor` for how to implement one.
  3531. *
  3532. * @publicApi
  3533. */
  3534. export declare const NG_VALUE_ACCESSOR: InjectionToken<readonly ControlValueAccessor[]>;
  3535. /**
  3536. * @description
  3537. * A base class that all `FormControl`-based directives extend. It binds a `FormControl`
  3538. * object to a DOM element.
  3539. *
  3540. * @publicApi
  3541. */
  3542. export declare abstract class NgControl extends AbstractControlDirective {
  3543. /**
  3544. * @description
  3545. * The name for the control
  3546. */
  3547. name: string | number | null;
  3548. /**
  3549. * @description
  3550. * The value accessor for the control
  3551. */
  3552. valueAccessor: ControlValueAccessor | null;
  3553. /**
  3554. * @description
  3555. * The callback method to update the model from the view when requested
  3556. *
  3557. * @param newValue The new value for the view
  3558. */
  3559. abstract viewToModelUpdate(newValue: any): void;
  3560. }
  3561. /**
  3562. * @description
  3563. * Directive automatically applied to Angular form controls that sets CSS classes
  3564. * based on control status.
  3565. *
  3566. * @usageNotes
  3567. *
  3568. * ### CSS classes applied
  3569. *
  3570. * The following classes are applied as the properties become true:
  3571. *
  3572. * * ng-valid
  3573. * * ng-invalid
  3574. * * ng-pending
  3575. * * ng-pristine
  3576. * * ng-dirty
  3577. * * ng-untouched
  3578. * * ng-touched
  3579. *
  3580. * @ngModule ReactiveFormsModule
  3581. * @ngModule FormsModule
  3582. * @publicApi
  3583. */
  3584. export declare class NgControlStatus extends AbstractControlStatus {
  3585. constructor(cd: NgControl);
  3586. static ɵfac: i0.ɵɵFactoryDeclaration<NgControlStatus, [{ self: true; }]>;
  3587. static ɵdir: i0.ɵɵDirectiveDeclaration<NgControlStatus, "[formControlName],[ngModel],[formControl]", never, {}, {}, never, never, false, never>;
  3588. }
  3589. /**
  3590. * @description
  3591. * Directive automatically applied to Angular form groups that sets CSS classes
  3592. * based on control status (valid/invalid/dirty/etc). On groups, this includes the additional
  3593. * class ng-submitted.
  3594. *
  3595. * @see `NgControlStatus`
  3596. *
  3597. * @ngModule ReactiveFormsModule
  3598. * @ngModule FormsModule
  3599. * @publicApi
  3600. */
  3601. export declare class NgControlStatusGroup extends AbstractControlStatus {
  3602. constructor(cd: ControlContainer);
  3603. static ɵfac: i0.ɵɵFactoryDeclaration<NgControlStatusGroup, [{ optional: true; self: true; }]>;
  3604. static ɵdir: i0.ɵɵDirectiveDeclaration<NgControlStatusGroup, "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]", never, {}, {}, never, never, false, never>;
  3605. }
  3606. declare const ngControlStatusHost: {
  3607. '[class.ng-untouched]': string;
  3608. '[class.ng-touched]': string;
  3609. '[class.ng-pristine]': string;
  3610. '[class.ng-dirty]': string;
  3611. '[class.ng-valid]': string;
  3612. '[class.ng-invalid]': string;
  3613. '[class.ng-pending]': string;
  3614. };
  3615. /**
  3616. * @description
  3617. * Creates a top-level `FormGroup` instance and binds it to a form
  3618. * to track aggregate form value and validation status.
  3619. *
  3620. * As soon as you import the `FormsModule`, this directive becomes active by default on
  3621. * all `<form>` tags. You don't need to add a special selector.
  3622. *
  3623. * You optionally export the directive into a local template variable using `ngForm` as the key
  3624. * (ex: `#myForm="ngForm"`). This is optional, but useful. Many properties from the underlying
  3625. * `FormGroup` instance are duplicated on the directive itself, so a reference to it
  3626. * gives you access to the aggregate value and validity status of the form, as well as
  3627. * user interaction properties like `dirty` and `touched`.
  3628. *
  3629. * To register child controls with the form, use `NgModel` with a `name`
  3630. * attribute. You may use `NgModelGroup` to create sub-groups within the form.
  3631. *
  3632. * If necessary, listen to the directive's `ngSubmit` event to be notified when the user has
  3633. * triggered a form submission. The `ngSubmit` event emits the original form
  3634. * submission event.
  3635. *
  3636. * In template driven forms, all `<form>` tags are automatically tagged as `NgForm`.
  3637. * To import the `FormsModule` but skip its usage in some forms,
  3638. * for example, to use native HTML5 validation, add the `ngNoForm` and the `<form>`
  3639. * tags won't create an `NgForm` directive. In reactive forms, using `ngNoForm` is
  3640. * unnecessary because the `<form>` tags are inert. In that case, you would
  3641. * refrain from using the `formGroup` directive.
  3642. *
  3643. * @usageNotes
  3644. *
  3645. * ### Listening for form submission
  3646. *
  3647. * The following example shows how to capture the form values from the "ngSubmit" event.
  3648. *
  3649. * {@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
  3650. *
  3651. * ### Setting the update options
  3652. *
  3653. * The following example shows you how to change the "updateOn" option from its default using
  3654. * ngFormOptions.
  3655. *
  3656. * ```html
  3657. * <form [ngFormOptions]="{updateOn: 'blur'}">
  3658. * <input name="one" ngModel> <!-- this ngModel will update on blur -->
  3659. * </form>
  3660. * ```
  3661. *
  3662. * ### Native DOM validation UI
  3663. *
  3664. * In order to prevent the native DOM form validation UI from interfering with Angular's form
  3665. * validation, Angular automatically adds the `novalidate` attribute on any `<form>` whenever
  3666. * `FormModule` or `ReactiveFormModule` are imported into the application.
  3667. * If you want to explicitly enable native DOM validation UI with Angular forms, you can add the
  3668. * `ngNativeValidate` attribute to the `<form>` element:
  3669. *
  3670. * ```html
  3671. * <form ngNativeValidate>
  3672. * ...
  3673. * </form>
  3674. * ```
  3675. *
  3676. * @ngModule FormsModule
  3677. * @publicApi
  3678. */
  3679. export declare class NgForm extends ControlContainer implements Form, AfterViewInit {
  3680. private callSetDisabledState?;
  3681. /**
  3682. * @description
  3683. * Returns whether the form submission has been triggered.
  3684. */
  3685. readonly submitted: boolean;
  3686. private _directives;
  3687. /**
  3688. * @description
  3689. * The `FormGroup` instance created for this form.
  3690. */
  3691. form: FormGroup;
  3692. /**
  3693. * @description
  3694. * Event emitter for the "ngSubmit" event
  3695. */
  3696. ngSubmit: EventEmitter<any>;
  3697. /**
  3698. * @description
  3699. * Tracks options for the `NgForm` instance.
  3700. *
  3701. * **updateOn**: Sets the default `updateOn` value for all child `NgModels` below it
  3702. * unless explicitly set by a child `NgModel` using `ngModelOptions`). Defaults to 'change'.
  3703. * Possible values: `'change'` | `'blur'` | `'submit'`.
  3704. *
  3705. */
  3706. options: {
  3707. updateOn?: FormHooks;
  3708. };
  3709. constructor(validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[], callSetDisabledState?: SetDisabledStateOption | undefined);
  3710. /** @nodoc */
  3711. ngAfterViewInit(): void;
  3712. /**
  3713. * @description
  3714. * The directive instance.
  3715. */
  3716. get formDirective(): Form;
  3717. /**
  3718. * @description
  3719. * The internal `FormGroup` instance.
  3720. */
  3721. get control(): FormGroup;
  3722. /**
  3723. * @description
  3724. * Returns an array representing the path to this group. Because this directive
  3725. * always lives at the top level of a form, it is always an empty array.
  3726. */
  3727. get path(): string[];
  3728. /**
  3729. * @description
  3730. * Returns a map of the controls in this group.
  3731. */
  3732. get controls(): {
  3733. [key: string]: AbstractControl;
  3734. };
  3735. /**
  3736. * @description
  3737. * Method that sets up the control directive in this group, re-calculates its value
  3738. * and validity, and adds the instance to the internal list of directives.
  3739. *
  3740. * @param dir The `NgModel` directive instance.
  3741. */
  3742. addControl(dir: NgModel): void;
  3743. /**
  3744. * @description
  3745. * Retrieves the `FormControl` instance from the provided `NgModel` directive.
  3746. *
  3747. * @param dir The `NgModel` directive instance.
  3748. */
  3749. getControl(dir: NgModel): FormControl;
  3750. /**
  3751. * @description
  3752. * Removes the `NgModel` instance from the internal list of directives
  3753. *
  3754. * @param dir The `NgModel` directive instance.
  3755. */
  3756. removeControl(dir: NgModel): void;
  3757. /**
  3758. * @description
  3759. * Adds a new `NgModelGroup` directive instance to the form.
  3760. *
  3761. * @param dir The `NgModelGroup` directive instance.
  3762. */
  3763. addFormGroup(dir: NgModelGroup): void;
  3764. /**
  3765. * @description
  3766. * Removes the `NgModelGroup` directive instance from the form.
  3767. *
  3768. * @param dir The `NgModelGroup` directive instance.
  3769. */
  3770. removeFormGroup(dir: NgModelGroup): void;
  3771. /**
  3772. * @description
  3773. * Retrieves the `FormGroup` for a provided `NgModelGroup` directive instance
  3774. *
  3775. * @param dir The `NgModelGroup` directive instance.
  3776. */
  3777. getFormGroup(dir: NgModelGroup): FormGroup;
  3778. /**
  3779. * Sets the new value for the provided `NgControl` directive.
  3780. *
  3781. * @param dir The `NgControl` directive instance.
  3782. * @param value The new value for the directive's control.
  3783. */
  3784. updateModel(dir: NgControl, value: any): void;
  3785. /**
  3786. * @description
  3787. * Sets the value for this `FormGroup`.
  3788. *
  3789. * @param value The new value
  3790. */
  3791. setValue(value: {
  3792. [key: string]: any;
  3793. }): void;
  3794. /**
  3795. * @description
  3796. * Method called when the "submit" event is triggered on the form.
  3797. * Triggers the `ngSubmit` emitter to emit the "submit" event as its payload.
  3798. *
  3799. * @param $event The "submit" event object
  3800. */
  3801. onSubmit($event: Event): boolean;
  3802. /**
  3803. * @description
  3804. * Method called when the "reset" event is triggered on the form.
  3805. */
  3806. onReset(): void;
  3807. /**
  3808. * @description
  3809. * Resets the form to an initial value and resets its submitted status.
  3810. *
  3811. * @param value The new value for the form.
  3812. */
  3813. resetForm(value?: any): void;
  3814. private _setUpdateStrategy;
  3815. private _findContainer;
  3816. static ɵfac: i0.ɵɵFactoryDeclaration<NgForm, [{ optional: true; self: true; }, { optional: true; self: true; }, { optional: true; }]>;
  3817. static ɵdir: i0.ɵɵDirectiveDeclaration<NgForm, "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", ["ngForm"], { "options": { "alias": "ngFormOptions"; "required": false; }; }, { "ngSubmit": "ngSubmit"; }, never, never, false, never>;
  3818. }
  3819. declare const ngGroupStatusHost: {
  3820. '[class.ng-submitted]': string;
  3821. '[class.ng-untouched]': string;
  3822. '[class.ng-touched]': string;
  3823. '[class.ng-pristine]': string;
  3824. '[class.ng-dirty]': string;
  3825. '[class.ng-valid]': string;
  3826. '[class.ng-invalid]': string;
  3827. '[class.ng-pending]': string;
  3828. };
  3829. /**
  3830. * @description
  3831. * Creates a `FormControl` instance from a [domain
  3832. * model](https://en.wikipedia.org/wiki/Domain_model) and binds it to a form control element.
  3833. *
  3834. * The `FormControl` instance tracks the value, user interaction, and
  3835. * validation status of the control and keeps the view synced with the model. If used
  3836. * within a parent form, the directive also registers itself with the form as a child
  3837. * control.
  3838. *
  3839. * This directive is used by itself or as part of a larger form. Use the
  3840. * `ngModel` selector to activate it.
  3841. *
  3842. * It accepts a domain model as an optional `Input`. If you have a one-way binding
  3843. * to `ngModel` with `[]` syntax, changing the domain model's value in the component
  3844. * class sets the value in the view. If you have a two-way binding with `[()]` syntax
  3845. * (also known as 'banana-in-a-box syntax'), the value in the UI always syncs back to
  3846. * the domain model in your class.
  3847. *
  3848. * To inspect the properties of the associated `FormControl` (like the validity state),
  3849. * export the directive into a local template variable using `ngModel` as the key (ex:
  3850. * `#myVar="ngModel"`). You can then access the control using the directive's `control` property.
  3851. * However, the most commonly used properties (like `valid` and `dirty`) also exist on the control
  3852. * for direct access. See a full list of properties directly available in
  3853. * `AbstractControlDirective`.
  3854. *
  3855. * @see `RadioControlValueAccessor`
  3856. * @see `SelectControlValueAccessor`
  3857. *
  3858. * @usageNotes
  3859. *
  3860. * ### Using ngModel on a standalone control
  3861. *
  3862. * The following examples show a simple standalone control using `ngModel`:
  3863. *
  3864. * {@example forms/ts/simpleNgModel/simple_ng_model_example.ts region='Component'}
  3865. *
  3866. * When using the `ngModel` within `<form>` tags, you'll also need to supply a `name` attribute
  3867. * so that the control can be registered with the parent form under that name.
  3868. *
  3869. * In the context of a parent form, it's often unnecessary to include one-way or two-way binding,
  3870. * as the parent form syncs the value for you. You access its properties by exporting it into a
  3871. * local template variable using `ngForm` such as (`#f="ngForm"`). Use the variable where
  3872. * needed on form submission.
  3873. *
  3874. * If you do need to populate initial values into your form, using a one-way binding for
  3875. * `ngModel` tends to be sufficient as long as you use the exported form's value rather
  3876. * than the domain model's value on submit.
  3877. *
  3878. * ### Using ngModel within a form
  3879. *
  3880. * The following example shows controls using `ngModel` within a form:
  3881. *
  3882. * {@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
  3883. *
  3884. * ### Using a standalone ngModel within a group
  3885. *
  3886. * The following example shows you how to use a standalone ngModel control
  3887. * within a form. This controls the display of the form, but doesn't contain form data.
  3888. *
  3889. * ```html
  3890. * <form>
  3891. * <input name="login" ngModel placeholder="Login">
  3892. * <input type="checkbox" ngModel [ngModelOptions]="{standalone: true}"> Show more options?
  3893. * </form>
  3894. * <!-- form value: {login: ''} -->
  3895. * ```
  3896. *
  3897. * ### Setting the ngModel `name` attribute through options
  3898. *
  3899. * The following example shows you an alternate way to set the name attribute. Here,
  3900. * an attribute identified as name is used within a custom form control component. To still be able
  3901. * to specify the NgModel's name, you must specify it using the `ngModelOptions` input instead.
  3902. *
  3903. * ```html
  3904. * <form>
  3905. * <my-custom-form-control name="Nancy" ngModel [ngModelOptions]="{name: 'user'}">
  3906. * </my-custom-form-control>
  3907. * </form>
  3908. * <!-- form value: {user: ''} -->
  3909. * ```
  3910. *
  3911. * @ngModule FormsModule
  3912. * @publicApi
  3913. */
  3914. export declare class NgModel extends NgControl implements OnChanges, OnDestroy {
  3915. private _changeDetectorRef?;
  3916. private callSetDisabledState?;
  3917. readonly control: FormControl;
  3918. /** @nodoc */
  3919. static ngAcceptInputType_isDisabled: boolean | string;
  3920. /**
  3921. * Internal reference to the view model value.
  3922. * @nodoc
  3923. */
  3924. viewModel: any;
  3925. /**
  3926. * @description
  3927. * Tracks the name bound to the directive. If a parent form exists, it
  3928. * uses this name as a key to retrieve this control's value.
  3929. */
  3930. name: string;
  3931. /**
  3932. * @description
  3933. * Tracks whether the control is disabled.
  3934. */
  3935. isDisabled: boolean;
  3936. /**
  3937. * @description
  3938. * Tracks the value bound to this directive.
  3939. */
  3940. model: any;
  3941. /**
  3942. * @description
  3943. * Tracks the configuration options for this `ngModel` instance.
  3944. *
  3945. * **name**: An alternative to setting the name attribute on the form control element. See
  3946. * the [example](api/forms/NgModel#using-ngmodel-on-a-standalone-control) for using `NgModel`
  3947. * as a standalone control.
  3948. *
  3949. * **standalone**: When set to true, the `ngModel` will not register itself with its parent form,
  3950. * and acts as if it's not in the form. Defaults to false. If no parent form exists, this option
  3951. * has no effect.
  3952. *
  3953. * **updateOn**: Defines the event upon which the form control value and validity update.
  3954. * Defaults to 'change'. Possible values: `'change'` | `'blur'` | `'submit'`.
  3955. *
  3956. */
  3957. options: {
  3958. name?: string;
  3959. standalone?: boolean;
  3960. updateOn?: FormHooks;
  3961. };
  3962. /**
  3963. * @description
  3964. * Event emitter for producing the `ngModelChange` event after
  3965. * the view model updates.
  3966. */
  3967. update: EventEmitter<any>;
  3968. constructor(parent: ControlContainer, validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[], valueAccessors: ControlValueAccessor[], _changeDetectorRef?: ChangeDetectorRef | null | undefined, callSetDisabledState?: SetDisabledStateOption | undefined);
  3969. /** @nodoc */
  3970. ngOnChanges(changes: SimpleChanges): void;
  3971. /** @nodoc */
  3972. ngOnDestroy(): void;
  3973. /**
  3974. * @description
  3975. * Returns an array that represents the path from the top-level form to this control.
  3976. * Each index is the string name of the control on that level.
  3977. */
  3978. get path(): string[];
  3979. /**
  3980. * @description
  3981. * The top-level directive for this control if present, otherwise null.
  3982. */
  3983. get formDirective(): any;
  3984. /**
  3985. * @description
  3986. * Sets the new value for the view model and emits an `ngModelChange` event.
  3987. *
  3988. * @param newValue The new value emitted by `ngModelChange`.
  3989. */
  3990. viewToModelUpdate(newValue: any): void;
  3991. private _setUpControl;
  3992. private _setUpdateStrategy;
  3993. private _isStandalone;
  3994. private _setUpStandalone;
  3995. private _checkForErrors;
  3996. private _checkParentType;
  3997. private _checkName;
  3998. private _updateValue;
  3999. private _updateDisabled;
  4000. private _getPath;
  4001. static ɵfac: i0.ɵɵFactoryDeclaration<NgModel, [{ optional: true; host: true; }, { optional: true; self: true; }, { optional: true; self: true; }, { optional: true; self: true; }, { optional: true; }, { optional: true; }]>;
  4002. static ɵdir: i0.ɵɵDirectiveDeclaration<NgModel, "[ngModel]:not([formControlName]):not([formControl])", ["ngModel"], { "name": { "alias": "name"; "required": false; }; "isDisabled": { "alias": "disabled"; "required": false; }; "model": { "alias": "ngModel"; "required": false; }; "options": { "alias": "ngModelOptions"; "required": false; }; }, { "update": "ngModelChange"; }, never, never, false, never>;
  4003. }
  4004. /**
  4005. * @description
  4006. * Creates and binds a `FormGroup` instance to a DOM element.
  4007. *
  4008. * This directive can only be used as a child of `NgForm` (within `<form>` tags).
  4009. *
  4010. * Use this directive to validate a sub-group of your form separately from the
  4011. * rest of your form, or if some values in your domain model make more sense
  4012. * to consume together in a nested object.
  4013. *
  4014. * Provide a name for the sub-group and it will become the key
  4015. * for the sub-group in the form's full value. If you need direct access, export the directive into
  4016. * a local template variable using `ngModelGroup` (ex: `#myGroup="ngModelGroup"`).
  4017. *
  4018. * @usageNotes
  4019. *
  4020. * ### Consuming controls in a grouping
  4021. *
  4022. * The following example shows you how to combine controls together in a sub-group
  4023. * of the form.
  4024. *
  4025. * {@example forms/ts/ngModelGroup/ng_model_group_example.ts region='Component'}
  4026. *
  4027. * @ngModule FormsModule
  4028. * @publicApi
  4029. */
  4030. export declare class NgModelGroup extends AbstractFormGroupDirective implements OnInit, OnDestroy {
  4031. /**
  4032. * @description
  4033. * Tracks the name of the `NgModelGroup` bound to the directive. The name corresponds
  4034. * to a key in the parent `NgForm`.
  4035. */
  4036. name: string;
  4037. constructor(parent: ControlContainer, validators: (Validator | ValidatorFn)[], asyncValidators: (AsyncValidator | AsyncValidatorFn)[]);
  4038. static ɵfac: i0.ɵɵFactoryDeclaration<NgModelGroup, [{ host: true; skipSelf: true; }, { optional: true; self: true; }, { optional: true; self: true; }]>;
  4039. static ɵdir: i0.ɵɵDirectiveDeclaration<NgModelGroup, "[ngModelGroup]", ["ngModelGroup"], { "name": { "alias": "ngModelGroup"; "required": false; }; }, {}, never, never, false, never>;
  4040. }
  4041. /**
  4042. * @description
  4043. * Marks `<option>` as dynamic, so Angular can be notified when options change.
  4044. *
  4045. * @see `SelectControlValueAccessor`
  4046. *
  4047. * @ngModule ReactiveFormsModule
  4048. * @ngModule FormsModule
  4049. * @publicApi
  4050. */
  4051. export declare class NgSelectOption implements OnDestroy {
  4052. private _element;
  4053. private _renderer;
  4054. private _select;
  4055. /**
  4056. * @description
  4057. * ID of the option element
  4058. */
  4059. id: string;
  4060. constructor(_element: ElementRef, _renderer: Renderer2, _select: SelectControlValueAccessor);
  4061. /**
  4062. * @description
  4063. * Tracks the value bound to the option element. Unlike the value binding,
  4064. * ngValue supports binding to objects.
  4065. */
  4066. set ngValue(value: any);
  4067. /**
  4068. * @description
  4069. * Tracks simple string values bound to the option element.
  4070. * For objects, use the `ngValue` input binding.
  4071. */
  4072. set value(value: any);
  4073. /** @nodoc */
  4074. ngOnDestroy(): void;
  4075. static ɵfac: i0.ɵɵFactoryDeclaration<NgSelectOption, [null, null, { optional: true; host: true; }]>;
  4076. static ɵdir: i0.ɵɵDirectiveDeclaration<NgSelectOption, "option", never, { "ngValue": { "alias": "ngValue"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, {}, never, never, false, never>;
  4077. }
  4078. /**
  4079. * @description
  4080. * `NonNullableFormBuilder` is similar to {@link FormBuilder}, but automatically constructed
  4081. * {@link FormControl} elements have `{nonNullable: true}` and are non-nullable.
  4082. *
  4083. * @publicApi
  4084. */
  4085. export declare abstract class NonNullableFormBuilder {
  4086. /**
  4087. * Similar to `FormBuilder#group`, except any implicitly constructed `FormControl`
  4088. * will be non-nullable (i.e. it will have `nonNullable` set to true). Note
  4089. * that already-constructed controls will not be altered.
  4090. */
  4091. abstract group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroup<{
  4092. [K in keyof T]: ɵElement<T[K], never>;
  4093. }>;
  4094. /**
  4095. * Similar to `FormBuilder#record`, except any implicitly constructed `FormControl`
  4096. * will be non-nullable (i.e. it will have `nonNullable` set to true). Note
  4097. * that already-constructed controls will not be altered.
  4098. */
  4099. abstract record<T>(controls: {
  4100. [key: string]: T;
  4101. }, options?: AbstractControlOptions | null): FormRecord<ɵElement<T, never>>;
  4102. /**
  4103. * Similar to `FormBuilder#array`, except any implicitly constructed `FormControl`
  4104. * will be non-nullable (i.e. it will have `nonNullable` set to true). Note
  4105. * that already-constructed controls will not be altered.
  4106. */
  4107. abstract array<T>(controls: Array<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormArray<ɵElement<T, never>>;
  4108. /**
  4109. * Similar to `FormBuilder#control`, except this overridden version of `control` forces
  4110. * `nonNullable` to be `true`, resulting in the control always being non-nullable.
  4111. */
  4112. abstract control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T>;
  4113. static ɵfac: i0.ɵɵFactoryDeclaration<NonNullableFormBuilder, never>;
  4114. static ɵprov: i0.ɵɵInjectableDeclaration<NonNullableFormBuilder>;
  4115. }
  4116. /**
  4117. * @description
  4118. * The `ControlValueAccessor` for writing a number value and listening to number input changes.
  4119. * The value accessor is used by the `FormControlDirective`, `FormControlName`, and `NgModel`
  4120. * directives.
  4121. *
  4122. * @usageNotes
  4123. *
  4124. * ### Using a number input with a reactive form.
  4125. *
  4126. * The following example shows how to use a number input with a reactive form.
  4127. *
  4128. * ```ts
  4129. * const totalCountControl = new FormControl();
  4130. * ```
  4131. *
  4132. * ```
  4133. * <input type="number" [formControl]="totalCountControl">
  4134. * ```
  4135. *
  4136. * @ngModule ReactiveFormsModule
  4137. * @ngModule FormsModule
  4138. * @publicApi
  4139. */
  4140. export declare class NumberValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor {
  4141. /**
  4142. * Sets the "value" property on the input element.
  4143. * @nodoc
  4144. */
  4145. writeValue(value: number): void;
  4146. /**
  4147. * Registers a function called when the control value changes.
  4148. * @nodoc
  4149. */
  4150. registerOnChange(fn: (_: number | null) => void): void;
  4151. static ɵfac: i0.ɵɵFactoryDeclaration<NumberValueAccessor, never>;
  4152. static ɵdir: i0.ɵɵDirectiveDeclaration<NumberValueAccessor, "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]", never, {}, {}, never, never, false, never>;
  4153. }
  4154. /**
  4155. * @description
  4156. * Provider which adds `PatternValidator` to the `NG_VALIDATORS` multi-provider list.
  4157. */
  4158. declare const PATTERN_VALIDATOR: any;
  4159. /**
  4160. * @description
  4161. * A directive that adds regex pattern validation to controls marked with the
  4162. * `pattern` attribute. The regex must match the entire control value.
  4163. * The directive is provided with the `NG_VALIDATORS` multi-provider list.
  4164. *
  4165. * @see [Form Validation](guide/form-validation)
  4166. *
  4167. * @usageNotes
  4168. *
  4169. * ### Adding a pattern validator
  4170. *
  4171. * The following example shows how to add a pattern validator to an input attached to an
  4172. * ngModel binding.
  4173. *
  4174. * ```html
  4175. * <input name="firstName" ngModel pattern="[a-zA-Z ]*">
  4176. * ```
  4177. *
  4178. * @ngModule ReactiveFormsModule
  4179. * @ngModule FormsModule
  4180. * @publicApi
  4181. */
  4182. export declare class PatternValidator extends AbstractValidatorDirective {
  4183. /**
  4184. * @description
  4185. * Tracks changes to the pattern bound to this directive.
  4186. */
  4187. pattern: string | RegExp;
  4188. static ɵfac: i0.ɵɵFactoryDeclaration<PatternValidator, never>;
  4189. static ɵdir: i0.ɵɵDirectiveDeclaration<PatternValidator, "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]", never, { "pattern": { "alias": "pattern"; "required": false; }; }, {}, never, never, false, never>;
  4190. }
  4191. /**
  4192. * Helper type to allow the compiler to accept [XXXX, { updateOn: string }] as a valid shorthand
  4193. * argument for .group()
  4194. */
  4195. declare interface PermissiveAbstractControlOptions extends Omit<AbstractControlOptions, 'updateOn'> {
  4196. updateOn?: string;
  4197. }
  4198. /**
  4199. * The compiler may not always be able to prove that the elements of the control config are a tuple
  4200. * (i.e. occur in a fixed order). This slightly looser type is used for inference, to catch cases
  4201. * where the compiler cannot prove order and position.
  4202. *
  4203. * For example, consider the simple case `fb.group({foo: ['bar', Validators.required]})`. The
  4204. * compiler will infer this as an array, not as a tuple.
  4205. */
  4206. declare type PermissiveControlConfig<T> = Array<T | FormControlState<T> | ValidatorConfig>;
  4207. /**
  4208. * @description
  4209. * Class used by Angular to track radio buttons. For internal use only.
  4210. */
  4211. declare class RadioControlRegistry {
  4212. private _accessors;
  4213. /**
  4214. * @description
  4215. * Adds a control to the internal registry. For internal use only.
  4216. */
  4217. add(control: NgControl, accessor: RadioControlValueAccessor): void;
  4218. /**
  4219. * @description
  4220. * Removes a control from the internal registry. For internal use only.
  4221. */
  4222. remove(accessor: RadioControlValueAccessor): void;
  4223. /**
  4224. * @description
  4225. * Selects a radio button. For internal use only.
  4226. */
  4227. select(accessor: RadioControlValueAccessor): void;
  4228. private _isSameGroup;
  4229. static ɵfac: i0.ɵɵFactoryDeclaration<RadioControlRegistry, never>;
  4230. static ɵprov: i0.ɵɵInjectableDeclaration<RadioControlRegistry>;
  4231. }
  4232. /**
  4233. * Internal-only NgModule that works as a host for the `RadioControlRegistry` tree-shakable
  4234. * provider. Note: the `InternalFormsSharedModule` can not be used here directly, since it's
  4235. * declared *after* the `RadioControlRegistry` class and the `providedIn` doesn't support
  4236. * `forwardRef` logic.
  4237. */
  4238. declare class RadioControlRegistryModule {
  4239. static ɵfac: i0.ɵɵFactoryDeclaration<RadioControlRegistryModule, never>;
  4240. static ɵmod: i0.ɵɵNgModuleDeclaration<RadioControlRegistryModule, never, never, never>;
  4241. static ɵinj: i0.ɵɵInjectorDeclaration<RadioControlRegistryModule>;
  4242. }
  4243. /**
  4244. * @description
  4245. * The `ControlValueAccessor` for writing radio control values and listening to radio control
  4246. * changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and
  4247. * `NgModel` directives.
  4248. *
  4249. * @usageNotes
  4250. *
  4251. * ### Using radio buttons with reactive form directives
  4252. *
  4253. * The follow example shows how to use radio buttons in a reactive form. When using radio buttons in
  4254. * a reactive form, radio buttons in the same group should have the same `formControlName`.
  4255. * Providing a `name` attribute is optional.
  4256. *
  4257. * {@example forms/ts/reactiveRadioButtons/reactive_radio_button_example.ts region='Reactive'}
  4258. *
  4259. * @ngModule ReactiveFormsModule
  4260. * @ngModule FormsModule
  4261. * @publicApi
  4262. */
  4263. export declare class RadioControlValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor, OnDestroy, OnInit {
  4264. private _registry;
  4265. private _injector;
  4266. private setDisabledStateFired;
  4267. /**
  4268. * The registered callback function called when a change event occurs on the input element.
  4269. * Note: we declare `onChange` here (also used as host listener) as a function with no arguments
  4270. * to override the `onChange` function (which expects 1 argument) in the parent
  4271. * `BaseControlValueAccessor` class.
  4272. * @nodoc
  4273. */
  4274. onChange: () => void;
  4275. /**
  4276. * @description
  4277. * Tracks the name of the radio input element.
  4278. */
  4279. name: string;
  4280. /**
  4281. * @description
  4282. * Tracks the name of the `FormControl` bound to the directive. The name corresponds
  4283. * to a key in the parent `FormGroup` or `FormArray`.
  4284. */
  4285. formControlName: string;
  4286. /**
  4287. * @description
  4288. * Tracks the value of the radio input element
  4289. */
  4290. value: any;
  4291. private callSetDisabledState;
  4292. constructor(renderer: Renderer2, elementRef: ElementRef, _registry: RadioControlRegistry, _injector: Injector);
  4293. /** @nodoc */
  4294. ngOnInit(): void;
  4295. /** @nodoc */
  4296. ngOnDestroy(): void;
  4297. /**
  4298. * Sets the "checked" property value on the radio input element.
  4299. * @nodoc
  4300. */
  4301. writeValue(value: any): void;
  4302. /**
  4303. * Registers a function called when the control value changes.
  4304. * @nodoc
  4305. */
  4306. registerOnChange(fn: (_: any) => {}): void;
  4307. /** @nodoc */
  4308. setDisabledState(isDisabled: boolean): void;
  4309. /**
  4310. * Sets the "value" on the radio input element and unchecks it.
  4311. *
  4312. * @param value
  4313. */
  4314. fireUncheck(value: any): void;
  4315. private _checkName;
  4316. static ɵfac: i0.ɵɵFactoryDeclaration<RadioControlValueAccessor, never>;
  4317. static ɵdir: i0.ɵɵDirectiveDeclaration<RadioControlValueAccessor, "input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]", never, { "name": { "alias": "name"; "required": false; }; "formControlName": { "alias": "formControlName"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, {}, never, never, false, never>;
  4318. }
  4319. /**
  4320. * @description
  4321. * The `ControlValueAccessor` for writing a range value and listening to range input changes.
  4322. * The value accessor is used by the `FormControlDirective`, `FormControlName`, and `NgModel`
  4323. * directives.
  4324. *
  4325. * @usageNotes
  4326. *
  4327. * ### Using a range input with a reactive form
  4328. *
  4329. * The following example shows how to use a range input with a reactive form.
  4330. *
  4331. * ```ts
  4332. * const ageControl = new FormControl();
  4333. * ```
  4334. *
  4335. * ```
  4336. * <input type="range" [formControl]="ageControl">
  4337. * ```
  4338. *
  4339. * @ngModule ReactiveFormsModule
  4340. * @ngModule FormsModule
  4341. * @publicApi
  4342. */
  4343. export declare class RangeValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor {
  4344. /**
  4345. * Sets the "value" property on the input element.
  4346. * @nodoc
  4347. */
  4348. writeValue(value: any): void;
  4349. /**
  4350. * Registers a function called when the control value changes.
  4351. * @nodoc
  4352. */
  4353. registerOnChange(fn: (_: number | null) => void): void;
  4354. static ɵfac: i0.ɵɵFactoryDeclaration<RangeValueAccessor, never>;
  4355. static ɵdir: i0.ɵɵDirectiveDeclaration<RangeValueAccessor, "input[type=range][formControlName],input[type=range][formControl],input[type=range][ngModel]", never, {}, {}, never, never, false, never>;
  4356. }
  4357. declare const REACTIVE_DRIVEN_DIRECTIVES: Type<any>[];
  4358. /**
  4359. * Exports the required infrastructure and directives for reactive forms,
  4360. * making them available for import by NgModules that import this module.
  4361. *
  4362. * Providers associated with this module:
  4363. * * `FormBuilder`
  4364. * * `RadioControlRegistry`
  4365. *
  4366. * @see [Forms Overview](guide/forms-overview)
  4367. * @see [Reactive Forms Guide](guide/reactive-forms)
  4368. *
  4369. * @publicApi
  4370. */
  4371. export declare class ReactiveFormsModule {
  4372. /**
  4373. * @description
  4374. * Provides options for configuring the reactive forms module.
  4375. *
  4376. * @param opts An object of configuration options
  4377. * * `warnOnNgModelWithFormControl` Configures when to emit a warning when an `ngModel`
  4378. * binding is used with reactive form directives.
  4379. * * `callSetDisabledState` Configures whether to `always` call `setDisabledState`, which is more
  4380. * correct, or to only call it `whenDisabled`, which is the legacy behavior.
  4381. */
  4382. static withConfig(opts: {
  4383. /** @deprecated as of v6 */ warnOnNgModelWithFormControl?: 'never' | 'once' | 'always';
  4384. callSetDisabledState?: SetDisabledStateOption;
  4385. }): ModuleWithProviders<ReactiveFormsModule>;
  4386. static ɵfac: i0.ɵɵFactoryDeclaration<ReactiveFormsModule, never>;
  4387. static ɵmod: i0.ɵɵNgModuleDeclaration<ReactiveFormsModule, [typeof i5_2.FormControlDirective, typeof i6_2.FormGroupDirective, typeof i7_2.FormControlName, typeof i8_2.FormGroupName, typeof i8_2.FormArrayName], never, [typeof i4_2.ɵInternalFormsSharedModule, typeof i5_2.FormControlDirective, typeof i6_2.FormGroupDirective, typeof i7_2.FormControlName, typeof i8_2.FormGroupName, typeof i8_2.FormArrayName]>;
  4388. static ɵinj: i0.ɵɵInjectorDeclaration<ReactiveFormsModule>;
  4389. }
  4390. /**
  4391. * @description
  4392. * Provider which adds `RequiredValidator` to the `NG_VALIDATORS` multi-provider list.
  4393. */
  4394. declare const REQUIRED_VALIDATOR: Provider;
  4395. /**
  4396. * @description
  4397. * A directive that adds the `required` validator to any controls marked with the
  4398. * `required` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  4399. *
  4400. * @see [Form Validation](guide/form-validation)
  4401. *
  4402. * @usageNotes
  4403. *
  4404. * ### Adding a required validator using template-driven forms
  4405. *
  4406. * ```
  4407. * <input name="fullName" ngModel required>
  4408. * ```
  4409. *
  4410. * @ngModule FormsModule
  4411. * @ngModule ReactiveFormsModule
  4412. * @publicApi
  4413. */
  4414. export declare class RequiredValidator extends AbstractValidatorDirective {
  4415. /**
  4416. * @description
  4417. * Tracks changes to the required attribute bound to this directive.
  4418. */
  4419. required: boolean | string;
  4420. /** @nodoc */
  4421. enabled(input: boolean): boolean;
  4422. static ɵfac: i0.ɵɵFactoryDeclaration<RequiredValidator, never>;
  4423. static ɵdir: i0.ɵɵDirectiveDeclaration<RequiredValidator, ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", never, { "required": { "alias": "required"; "required": false; }; }, {}, never, never, false, never>;
  4424. }
  4425. /**
  4426. * @description
  4427. * The `ControlValueAccessor` for writing select control values and listening to select control
  4428. * changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and
  4429. * `NgModel` directives.
  4430. *
  4431. * @usageNotes
  4432. *
  4433. * ### Using select controls in a reactive form
  4434. *
  4435. * The following examples show how to use a select control in a reactive form.
  4436. *
  4437. * {@example forms/ts/reactiveSelectControl/reactive_select_control_example.ts region='Component'}
  4438. *
  4439. * ### Using select controls in a template-driven form
  4440. *
  4441. * To use a select in a template-driven form, simply add an `ngModel` and a `name`
  4442. * attribute to the main `<select>` tag.
  4443. *
  4444. * {@example forms/ts/selectControl/select_control_example.ts region='Component'}
  4445. *
  4446. * ### Customizing option selection
  4447. *
  4448. * Angular uses object identity to select option. It's possible for the identities of items
  4449. * to change while the data does not. This can happen, for example, if the items are produced
  4450. * from an RPC to the server, and that RPC is re-run. Even if the data hasn't changed, the
  4451. * second response will produce objects with different identities.
  4452. *
  4453. * To customize the default option comparison algorithm, `<select>` supports `compareWith` input.
  4454. * `compareWith` takes a **function** which has two arguments: `option1` and `option2`.
  4455. * If `compareWith` is given, Angular selects option by the return value of the function.
  4456. *
  4457. * ```ts
  4458. * const selectedCountriesControl = new FormControl();
  4459. * ```
  4460. *
  4461. * ```
  4462. * <select [compareWith]="compareFn" [formControl]="selectedCountriesControl">
  4463. * <option *ngFor="let country of countries" [ngValue]="country">
  4464. * {{country.name}}
  4465. * </option>
  4466. * </select>
  4467. *
  4468. * compareFn(c1: Country, c2: Country): boolean {
  4469. * return c1 && c2 ? c1.id === c2.id : c1 === c2;
  4470. * }
  4471. * ```
  4472. *
  4473. * **Note:** We listen to the 'change' event because 'input' events aren't fired
  4474. * for selects in IE, see:
  4475. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event#browser_compatibility
  4476. *
  4477. * @ngModule ReactiveFormsModule
  4478. * @ngModule FormsModule
  4479. * @publicApi
  4480. */
  4481. export declare class SelectControlValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor {
  4482. /** @nodoc */
  4483. value: any;
  4484. /**
  4485. * @description
  4486. * Tracks the option comparison algorithm for tracking identities when
  4487. * checking for changes.
  4488. */
  4489. set compareWith(fn: (o1: any, o2: any) => boolean);
  4490. private _compareWith;
  4491. /**
  4492. * Sets the "value" property on the select element.
  4493. * @nodoc
  4494. */
  4495. writeValue(value: any): void;
  4496. /**
  4497. * Registers a function called when the control value changes.
  4498. * @nodoc
  4499. */
  4500. registerOnChange(fn: (value: any) => any): void;
  4501. static ɵfac: i0.ɵɵFactoryDeclaration<SelectControlValueAccessor, never>;
  4502. static ɵdir: i0.ɵɵDirectiveDeclaration<SelectControlValueAccessor, "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", never, { "compareWith": { "alias": "compareWith"; "required": false; }; }, {}, never, never, false, never>;
  4503. }
  4504. /**
  4505. * @description
  4506. * The `ControlValueAccessor` for writing multi-select control values and listening to multi-select
  4507. * control changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and
  4508. * `NgModel` directives.
  4509. *
  4510. * @see `SelectControlValueAccessor`
  4511. *
  4512. * @usageNotes
  4513. *
  4514. * ### Using a multi-select control
  4515. *
  4516. * The follow example shows you how to use a multi-select control with a reactive form.
  4517. *
  4518. * ```ts
  4519. * const countryControl = new FormControl();
  4520. * ```
  4521. *
  4522. * ```
  4523. * <select multiple name="countries" [formControl]="countryControl">
  4524. * <option *ngFor="let country of countries" [ngValue]="country">
  4525. * {{ country.name }}
  4526. * </option>
  4527. * </select>
  4528. * ```
  4529. *
  4530. * ### Customizing option selection
  4531. *
  4532. * To customize the default option comparison algorithm, `<select>` supports `compareWith` input.
  4533. * See the `SelectControlValueAccessor` for usage.
  4534. *
  4535. * @ngModule ReactiveFormsModule
  4536. * @ngModule FormsModule
  4537. * @publicApi
  4538. */
  4539. export declare class SelectMultipleControlValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor {
  4540. /**
  4541. * The current value.
  4542. * @nodoc
  4543. */
  4544. value: any;
  4545. /**
  4546. * @description
  4547. * Tracks the option comparison algorithm for tracking identities when
  4548. * checking for changes.
  4549. */
  4550. set compareWith(fn: (o1: any, o2: any) => boolean);
  4551. private _compareWith;
  4552. /**
  4553. * Sets the "value" property on one or of more of the select's options.
  4554. * @nodoc
  4555. */
  4556. writeValue(value: any): void;
  4557. /**
  4558. * Registers a function called when the control value changes
  4559. * and writes an array of the selected options.
  4560. * @nodoc
  4561. */
  4562. registerOnChange(fn: (value: any) => any): void;
  4563. static ɵfac: i0.ɵɵFactoryDeclaration<SelectMultipleControlValueAccessor, never>;
  4564. static ɵdir: i0.ɵɵDirectiveDeclaration<SelectMultipleControlValueAccessor, "select[multiple][formControlName],select[multiple][formControl],select[multiple][ngModel]", never, { "compareWith": { "alias": "compareWith"; "required": false; }; }, {}, never, never, false, never>;
  4565. }
  4566. /**
  4567. * The type for CALL_SET_DISABLED_STATE. If `always`, then ControlValueAccessor will always call
  4568. * `setDisabledState` when attached, which is the most correct behavior. Otherwise, it will only be
  4569. * called when disabled, which is the legacy behavior for compatibility.
  4570. *
  4571. * @publicApi
  4572. * @see `FormsModule.withConfig`
  4573. */
  4574. export declare type SetDisabledStateOption = 'whenDisabledForLegacyCode' | 'always';
  4575. declare const SHARED_FORM_DIRECTIVES: Type<any>[];
  4576. declare const TEMPLATE_DRIVEN_DIRECTIVES: Type<any>[];
  4577. /**
  4578. * UntypedFormArray is a non-strongly-typed version of `FormArray`, which
  4579. * permits heterogenous controls.
  4580. */
  4581. export declare type UntypedFormArray = FormArray<any>;
  4582. export declare const UntypedFormArray: UntypedFormArrayCtor;
  4583. declare interface UntypedFormArrayCtor {
  4584. new (controls: AbstractControl[], validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormArray;
  4585. /**
  4586. * The presence of an explicit `prototype` property provides backwards-compatibility for apps that
  4587. * manually inspect the prototype chain.
  4588. */
  4589. prototype: FormArray<any>;
  4590. }
  4591. /**
  4592. * UntypedFormBuilder is the same as `FormBuilder`, but it provides untyped controls.
  4593. */
  4594. export declare class UntypedFormBuilder extends FormBuilder {
  4595. /**
  4596. * Like `FormBuilder#group`, except the resulting group is untyped.
  4597. */
  4598. group(controlsConfig: {
  4599. [key: string]: any;
  4600. }, options?: AbstractControlOptions | null): UntypedFormGroup;
  4601. /**
  4602. * @deprecated This API is not typesafe and can result in issues with Closure Compiler renaming.
  4603. * Use the `FormBuilder#group` overload with `AbstractControlOptions` instead.
  4604. */
  4605. group(controlsConfig: {
  4606. [key: string]: any;
  4607. }, options: {
  4608. [key: string]: any;
  4609. }): UntypedFormGroup;
  4610. /**
  4611. * Like `FormBuilder#control`, except the resulting control is untyped.
  4612. */
  4613. control(formState: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormControl;
  4614. /**
  4615. * Like `FormBuilder#array`, except the resulting array is untyped.
  4616. */
  4617. array(controlsConfig: any[], validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormArray;
  4618. static ɵfac: i0.ɵɵFactoryDeclaration<UntypedFormBuilder, never>;
  4619. static ɵprov: i0.ɵɵInjectableDeclaration<UntypedFormBuilder>;
  4620. }
  4621. /**
  4622. * UntypedFormControl is a non-strongly-typed version of `FormControl`.
  4623. */
  4624. export declare type UntypedFormControl = FormControl<any>;
  4625. export declare const UntypedFormControl: UntypedFormControlCtor;
  4626. declare interface UntypedFormControlCtor {
  4627. new (): UntypedFormControl;
  4628. new (formState?: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormControl;
  4629. /**
  4630. * The presence of an explicit `prototype` property provides backwards-compatibility for apps that
  4631. * manually inspect the prototype chain.
  4632. */
  4633. prototype: FormControl<any>;
  4634. }
  4635. /**
  4636. * UntypedFormGroup is a non-strongly-typed version of `FormGroup`.
  4637. */
  4638. export declare type UntypedFormGroup = FormGroup<any>;
  4639. export declare const UntypedFormGroup: UntypedFormGroupCtor;
  4640. declare interface UntypedFormGroupCtor {
  4641. new (controls: {
  4642. [key: string]: AbstractControl;
  4643. }, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormGroup;
  4644. /**
  4645. * The presence of an explicit `prototype` property provides backwards-compatibility for apps that
  4646. * manually inspect the prototype chain.
  4647. */
  4648. prototype: FormGroup<any>;
  4649. }
  4650. /**
  4651. * @description
  4652. * Defines the map of errors returned from failed validation checks.
  4653. *
  4654. * @publicApi
  4655. */
  4656. export declare type ValidationErrors = {
  4657. [key: string]: any;
  4658. };
  4659. /**
  4660. * @description
  4661. * An interface implemented by classes that perform synchronous validation.
  4662. *
  4663. * @usageNotes
  4664. *
  4665. * ### Provide a custom validator
  4666. *
  4667. * The following example implements the `Validator` interface to create a
  4668. * validator directive with a custom error key.
  4669. *
  4670. * ```typescript
  4671. * @Directive({
  4672. * selector: '[customValidator]',
  4673. * providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
  4674. * })
  4675. * class CustomValidatorDirective implements Validator {
  4676. * validate(control: AbstractControl): ValidationErrors|null {
  4677. * return {'custom': true};
  4678. * }
  4679. * }
  4680. * ```
  4681. *
  4682. * @publicApi
  4683. */
  4684. export declare interface Validator {
  4685. /**
  4686. * @description
  4687. * Method that performs synchronous validation against the provided control.
  4688. *
  4689. * @param control The control to validate against.
  4690. *
  4691. * @returns A map of validation errors if validation fails,
  4692. * otherwise null.
  4693. */
  4694. validate(control: AbstractControl): ValidationErrors | null;
  4695. /**
  4696. * @description
  4697. * Registers a callback function to call when the validator inputs change.
  4698. *
  4699. * @param fn The callback function
  4700. */
  4701. registerOnValidatorChange?(fn: () => void): void;
  4702. }
  4703. /**
  4704. * The union of all validator types that can be accepted by a ControlConfig.
  4705. */
  4706. declare type ValidatorConfig = ValidatorFn | AsyncValidatorFn | ValidatorFn[] | AsyncValidatorFn[];
  4707. /**
  4708. * @description
  4709. * A function that receives a control and synchronously returns a map of
  4710. * validation errors if present, otherwise null.
  4711. *
  4712. * @publicApi
  4713. */
  4714. export declare interface ValidatorFn {
  4715. (control: AbstractControl): ValidationErrors | null;
  4716. }
  4717. /**
  4718. * @description
  4719. * Provides a set of built-in validators that can be used by form controls.
  4720. *
  4721. * A validator is a function that processes a `FormControl` or collection of
  4722. * controls and returns an error map or null. A null map means that validation has passed.
  4723. *
  4724. * @see [Form Validation](/guide/form-validation)
  4725. *
  4726. * @publicApi
  4727. */
  4728. export declare class Validators {
  4729. /**
  4730. * @description
  4731. * Validator that requires the control's value to be greater than or equal to the provided number.
  4732. *
  4733. * @usageNotes
  4734. *
  4735. * ### Validate against a minimum of 3
  4736. *
  4737. * ```typescript
  4738. * const control = new FormControl(2, Validators.min(3));
  4739. *
  4740. * console.log(control.errors); // {min: {min: 3, actual: 2}}
  4741. * ```
  4742. *
  4743. * @returns A validator function that returns an error map with the
  4744. * `min` property if the validation check fails, otherwise `null`.
  4745. *
  4746. * @see `updateValueAndValidity()`
  4747. *
  4748. */
  4749. static min(min: number): ValidatorFn;
  4750. /**
  4751. * @description
  4752. * Validator that requires the control's value to be less than or equal to the provided number.
  4753. *
  4754. * @usageNotes
  4755. *
  4756. * ### Validate against a maximum of 15
  4757. *
  4758. * ```typescript
  4759. * const control = new FormControl(16, Validators.max(15));
  4760. *
  4761. * console.log(control.errors); // {max: {max: 15, actual: 16}}
  4762. * ```
  4763. *
  4764. * @returns A validator function that returns an error map with the
  4765. * `max` property if the validation check fails, otherwise `null`.
  4766. *
  4767. * @see `updateValueAndValidity()`
  4768. *
  4769. */
  4770. static max(max: number): ValidatorFn;
  4771. /**
  4772. * @description
  4773. * Validator that requires the control have a non-empty value.
  4774. *
  4775. * @usageNotes
  4776. *
  4777. * ### Validate that the field is non-empty
  4778. *
  4779. * ```typescript
  4780. * const control = new FormControl('', Validators.required);
  4781. *
  4782. * console.log(control.errors); // {required: true}
  4783. * ```
  4784. *
  4785. * @returns An error map with the `required` property
  4786. * if the validation check fails, otherwise `null`.
  4787. *
  4788. * @see `updateValueAndValidity()`
  4789. *
  4790. */
  4791. static required(control: AbstractControl): ValidationErrors | null;
  4792. /**
  4793. * @description
  4794. * Validator that requires the control's value be true. This validator is commonly
  4795. * used for required checkboxes.
  4796. *
  4797. * @usageNotes
  4798. *
  4799. * ### Validate that the field value is true
  4800. *
  4801. * ```typescript
  4802. * const control = new FormControl('some value', Validators.requiredTrue);
  4803. *
  4804. * console.log(control.errors); // {required: true}
  4805. * ```
  4806. *
  4807. * @returns An error map that contains the `required` property
  4808. * set to `true` if the validation check fails, otherwise `null`.
  4809. *
  4810. * @see `updateValueAndValidity()`
  4811. *
  4812. */
  4813. static requiredTrue(control: AbstractControl): ValidationErrors | null;
  4814. /**
  4815. * @description
  4816. * Validator that requires the control's value pass an email validation test.
  4817. *
  4818. * Tests the value using a [regular
  4819. * expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
  4820. * pattern suitable for common use cases. The pattern is based on the definition of a valid email
  4821. * address in the [WHATWG HTML
  4822. * specification](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address) with
  4823. * some enhancements to incorporate more RFC rules (such as rules related to domain names and the
  4824. * lengths of different parts of the address).
  4825. *
  4826. * The differences from the WHATWG version include:
  4827. * - Disallow `local-part` (the part before the `@` symbol) to begin or end with a period (`.`).
  4828. * - Disallow `local-part` to be longer than 64 characters.
  4829. * - Disallow the whole address to be longer than 254 characters.
  4830. *
  4831. * If this pattern does not satisfy your business needs, you can use `Validators.pattern()` to
  4832. * validate the value against a different pattern.
  4833. *
  4834. * @usageNotes
  4835. *
  4836. * ### Validate that the field matches a valid email pattern
  4837. *
  4838. * ```typescript
  4839. * const control = new FormControl('bad@', Validators.email);
  4840. *
  4841. * console.log(control.errors); // {email: true}
  4842. * ```
  4843. *
  4844. * @returns An error map with the `email` property
  4845. * if the validation check fails, otherwise `null`.
  4846. *
  4847. * @see `updateValueAndValidity()`
  4848. *
  4849. */
  4850. static email(control: AbstractControl): ValidationErrors | null;
  4851. /**
  4852. * @description
  4853. * Validator that requires the length of the control's value to be greater than or equal
  4854. * to the provided minimum length. This validator is also provided by default if you use the
  4855. * the HTML5 `minlength` attribute. Note that the `minLength` validator is intended to be used
  4856. * only for types that have a numeric `length` property, such as strings or arrays. The
  4857. * `minLength` validator logic is also not invoked for values when their `length` property is 0
  4858. * (for example in case of an empty string or an empty array), to support optional controls. You
  4859. * can use the standard `required` validator if empty values should not be considered valid.
  4860. *
  4861. * @usageNotes
  4862. *
  4863. * ### Validate that the field has a minimum of 3 characters
  4864. *
  4865. * ```typescript
  4866. * const control = new FormControl('ng', Validators.minLength(3));
  4867. *
  4868. * console.log(control.errors); // {minlength: {requiredLength: 3, actualLength: 2}}
  4869. * ```
  4870. *
  4871. * ```html
  4872. * <input minlength="5">
  4873. * ```
  4874. *
  4875. * @returns A validator function that returns an error map with the
  4876. * `minlength` property if the validation check fails, otherwise `null`.
  4877. *
  4878. * @see `updateValueAndValidity()`
  4879. *
  4880. */
  4881. static minLength(minLength: number): ValidatorFn;
  4882. /**
  4883. * @description
  4884. * Validator that requires the length of the control's value to be less than or equal
  4885. * to the provided maximum length. This validator is also provided by default if you use the
  4886. * the HTML5 `maxlength` attribute. Note that the `maxLength` validator is intended to be used
  4887. * only for types that have a numeric `length` property, such as strings or arrays.
  4888. *
  4889. * @usageNotes
  4890. *
  4891. * ### Validate that the field has maximum of 5 characters
  4892. *
  4893. * ```typescript
  4894. * const control = new FormControl('Angular', Validators.maxLength(5));
  4895. *
  4896. * console.log(control.errors); // {maxlength: {requiredLength: 5, actualLength: 7}}
  4897. * ```
  4898. *
  4899. * ```html
  4900. * <input maxlength="5">
  4901. * ```
  4902. *
  4903. * @returns A validator function that returns an error map with the
  4904. * `maxlength` property if the validation check fails, otherwise `null`.
  4905. *
  4906. * @see `updateValueAndValidity()`
  4907. *
  4908. */
  4909. static maxLength(maxLength: number): ValidatorFn;
  4910. /**
  4911. * @description
  4912. * Validator that requires the control's value to match a regex pattern. This validator is also
  4913. * provided by default if you use the HTML5 `pattern` attribute.
  4914. *
  4915. * @usageNotes
  4916. *
  4917. * ### Validate that the field only contains letters or spaces
  4918. *
  4919. * ```typescript
  4920. * const control = new FormControl('1', Validators.pattern('[a-zA-Z ]*'));
  4921. *
  4922. * console.log(control.errors); // {pattern: {requiredPattern: '^[a-zA-Z ]*$', actualValue: '1'}}
  4923. * ```
  4924. *
  4925. * ```html
  4926. * <input pattern="[a-zA-Z ]*">
  4927. * ```
  4928. *
  4929. * ### Pattern matching with the global or sticky flag
  4930. *
  4931. * `RegExp` objects created with the `g` or `y` flags that are passed into `Validators.pattern`
  4932. * can produce different results on the same input when validations are run consecutively. This is
  4933. * due to how the behavior of `RegExp.prototype.test` is
  4934. * specified in [ECMA-262](https://tc39.es/ecma262/#sec-regexpbuiltinexec)
  4935. * (`RegExp` preserves the index of the last match when the global or sticky flag is used).
  4936. * Due to this behavior, it is recommended that when using
  4937. * `Validators.pattern` you **do not** pass in a `RegExp` object with either the global or sticky
  4938. * flag enabled.
  4939. *
  4940. * ```typescript
  4941. * // Not recommended (since the `g` flag is used)
  4942. * const controlOne = new FormControl('1', Validators.pattern(/foo/g));
  4943. *
  4944. * // Good
  4945. * const controlTwo = new FormControl('1', Validators.pattern(/foo/));
  4946. * ```
  4947. *
  4948. * @param pattern A regular expression to be used as is to test the values, or a string.
  4949. * If a string is passed, the `^` character is prepended and the `$` character is
  4950. * appended to the provided string (if not already present), and the resulting regular
  4951. * expression is used to test the values.
  4952. *
  4953. * @returns A validator function that returns an error map with the
  4954. * `pattern` property if the validation check fails, otherwise `null`.
  4955. *
  4956. * @see `updateValueAndValidity()`
  4957. *
  4958. */
  4959. static pattern(pattern: string | RegExp): ValidatorFn;
  4960. /**
  4961. * @description
  4962. * Validator that performs no operation.
  4963. *
  4964. * @see `updateValueAndValidity()`
  4965. *
  4966. */
  4967. static nullValidator(control: AbstractControl): ValidationErrors | null;
  4968. /**
  4969. * @description
  4970. * Compose multiple validators into a single function that returns the union
  4971. * of the individual error maps for the provided control.
  4972. *
  4973. * @returns A validator function that returns an error map with the
  4974. * merged error maps of the validators if the validation check fails, otherwise `null`.
  4975. *
  4976. * @see `updateValueAndValidity()`
  4977. *
  4978. */
  4979. static compose(validators: null): null;
  4980. static compose(validators: (ValidatorFn | null | undefined)[]): ValidatorFn | null;
  4981. /**
  4982. * @description
  4983. * Compose multiple async validators into a single function that returns the union
  4984. * of the individual error objects for the provided control.
  4985. *
  4986. * @returns A validator function that returns an error map with the
  4987. * merged error objects of the async validators if the validation check fails, otherwise `null`.
  4988. *
  4989. * @see `updateValueAndValidity()`
  4990. *
  4991. */
  4992. static composeAsync(validators: (AsyncValidatorFn | null)[]): AsyncValidatorFn | null;
  4993. }
  4994. /**
  4995. * @publicApi
  4996. */
  4997. export declare const VERSION: Version;
  4998. /**
  4999. * CoerceStrArrToNumArr accepts an array of strings, and converts any numeric string to a number.
  5000. */
  5001. export declare type ɵCoerceStrArrToNumArr<S> = S extends [infer Head, ...infer Tail] ? Head extends `${number}` ? [
  5002. number,
  5003. ...ɵCoerceStrArrToNumArr<Tail>
  5004. ] : [
  5005. Head,
  5006. ...ɵCoerceStrArrToNumArr<Tail>
  5007. ] : [
  5008. ];
  5009. /**
  5010. * FormBuilder accepts values in various container shapes, as well as raw values.
  5011. * Element returns the appropriate corresponding model class, given the container T.
  5012. * The flag N, if not never, makes the resulting `FormControl` have N in its type.
  5013. */
  5014. export declare type ɵElement<T, N extends null> = [
  5015. T
  5016. ] extends [FormControl<infer U>] ? FormControl<U> : [
  5017. T
  5018. ] extends [FormControl<infer U> | undefined] ? FormControl<U> : [
  5019. T
  5020. ] extends [FormGroup<infer U>] ? FormGroup<U> : [
  5021. T
  5022. ] extends [FormGroup<infer U> | undefined] ? FormGroup<U> : [
  5023. T
  5024. ] extends [FormRecord<infer U>] ? FormRecord<U> : [
  5025. T
  5026. ] extends [FormRecord<infer U> | undefined] ? FormRecord<U> : [
  5027. T
  5028. ] extends [FormArray<infer U>] ? FormArray<U> : [
  5029. T
  5030. ] extends [FormArray<infer U> | undefined] ? FormArray<U> : [
  5031. T
  5032. ] extends [AbstractControl<infer U>] ? AbstractControl<U> : [
  5033. T
  5034. ] extends [AbstractControl<infer U> | undefined] ? AbstractControl<U> : [
  5035. T
  5036. ] extends [FormControlState<infer U>] ? FormControl<U | N> : [
  5037. T
  5038. ] extends [PermissiveControlConfig<infer U>] ? FormControl<Exclude<U, ValidatorConfig | PermissiveAbstractControlOptions> | N> : FormControl<T | N>;
  5039. /**
  5040. * FormArrayRawValue extracts the type of `.getRawValue()` from a FormArray's element type, and
  5041. * wraps it in an array. The untyped case falls back to any[].
  5042. *
  5043. * Angular uses this type internally to support Typed Forms; do not use it directly.
  5044. */
  5045. export declare type ɵFormArrayRawValue<T extends AbstractControl<any>> = ɵTypedOrUntyped<T, Array<ɵRawValue<T>>, any[]>;
  5046. /**
  5047. * FormArrayValue extracts the type of `.value` from a FormArray's element type, and wraps it in an
  5048. * array.
  5049. *
  5050. * Angular uses this type internally to support Typed Forms; do not use it directly. The untyped
  5051. * case falls back to any[].
  5052. */
  5053. export declare type ɵFormArrayValue<T extends AbstractControl<any>> = ɵTypedOrUntyped<T, Array<ɵValue<T>>, any[]>;
  5054. /**
  5055. * Various available constructors for `FormControl`.
  5056. * Do not use this interface directly. Instead, use `FormControl`:
  5057. * ```
  5058. * const fc = new FormControl('foo');
  5059. * ```
  5060. * This symbol is prefixed with ɵ to make plain that it is an internal symbol.
  5061. */
  5062. export declare interface ɵFormControlCtor {
  5063. /**
  5064. * Construct a FormControl with no initial value or validators.
  5065. */
  5066. new (): FormControl<any>;
  5067. /**
  5068. * Creates a new `FormControl` instance.
  5069. *
  5070. * @param formState Initializes the control with an initial value,
  5071. * or an object that defines the initial value and disabled state.
  5072. *
  5073. * @param validatorOrOpts A synchronous validator function, or an array of
  5074. * such functions, or a `FormControlOptions` object that contains validation functions
  5075. * and a validation trigger.
  5076. *
  5077. * @param asyncValidator A single async validator or array of async validator functions
  5078. */
  5079. new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
  5080. nonNullable: true;
  5081. }): FormControl<T>;
  5082. /**
  5083. * @deprecated Use `nonNullable` instead.
  5084. */
  5085. new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
  5086. initialValueIsDefault: true;
  5087. }): FormControl<T>;
  5088. /**
  5089. * @deprecated When passing an `options` argument, the `asyncValidator` argument has no effect.
  5090. */
  5091. new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions, asyncValidator: AsyncValidatorFn | AsyncValidatorFn[]): FormControl<T | null>;
  5092. new <T = any>(value: FormControlState<T> | T, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T | null>;
  5093. /**
  5094. * The presence of an explicit `prototype` property provides backwards-compatibility for apps that
  5095. * manually inspect the prototype chain.
  5096. */
  5097. prototype: FormControl<any>;
  5098. }
  5099. /**
  5100. * FormGroupRawValue extracts the type of `.getRawValue()` from a FormGroup's inner object type. The
  5101. * untyped case falls back to {[key: string]: any}.
  5102. *
  5103. * Angular uses this type internally to support Typed Forms; do not use it directly.
  5104. *
  5105. * For internal use only.
  5106. */
  5107. export declare type ɵFormGroupRawValue<T extends {
  5108. [K in keyof T]?: AbstractControl<any>;
  5109. }> = ɵTypedOrUntyped<T, {
  5110. [K in keyof T]: ɵRawValue<T[K]>;
  5111. }, {
  5112. [key: string]: any;
  5113. }>;
  5114. /**
  5115. * FormGroupValue extracts the type of `.value` from a FormGroup's inner object type. The untyped
  5116. * case falls back to {[key: string]: any}.
  5117. *
  5118. * Angular uses this type internally to support Typed Forms; do not use it directly.
  5119. *
  5120. * For internal use only.
  5121. */
  5122. export declare type ɵFormGroupValue<T extends {
  5123. [K in keyof T]?: AbstractControl<any>;
  5124. }> = ɵTypedOrUntyped<T, Partial<{
  5125. [K in keyof T]: ɵValue<T[K]>;
  5126. }>, {
  5127. [key: string]: any;
  5128. }>;
  5129. /**
  5130. * GetProperty takes a type T and some property names or indices K.
  5131. * If K is a dot-separated string, it is tokenized into an array before proceeding.
  5132. * Then, the type of the nested property at K is computed: T[K[0]][K[1]][K[2]]...
  5133. * This works with both objects, which are indexed by property name, and arrays, which are indexed
  5134. * numerically.
  5135. *
  5136. * For internal use only.
  5137. */
  5138. export declare type ɵGetProperty<T, K> = K extends string ? ɵGetProperty<T, ɵCoerceStrArrToNumArr<ɵTokenize<K, '.'>>> : ɵWriteable<K> extends Array<string | number> ? ɵNavigate<T, ɵWriteable<K>> : any;
  5139. /**
  5140. * Internal module used for sharing directives between FormsModule and ReactiveFormsModule
  5141. */
  5142. export declare class ɵInternalFormsSharedModule {
  5143. static ɵfac: i0.ɵɵFactoryDeclaration<ɵInternalFormsSharedModule, never>;
  5144. static ɵmod: i0.ɵɵNgModuleDeclaration<ɵInternalFormsSharedModule, [typeof i1.ɵNgNoValidate, typeof i2.NgSelectOption, typeof i3.ɵNgSelectMultipleOption, typeof i4.DefaultValueAccessor, typeof i5.NumberValueAccessor, typeof i6.RangeValueAccessor, typeof i7.CheckboxControlValueAccessor, typeof i2.SelectControlValueAccessor, typeof i3.SelectMultipleControlValueAccessor, typeof i8.RadioControlValueAccessor, typeof i9.NgControlStatus, typeof i9.NgControlStatusGroup, typeof i10.RequiredValidator, typeof i10.MinLengthValidator, typeof i10.MaxLengthValidator, typeof i10.PatternValidator, typeof i10.CheckboxRequiredValidator, typeof i10.EmailValidator, typeof i10.MinValidator, typeof i10.MaxValidator], [typeof i8.RadioControlRegistryModule], [typeof i1.ɵNgNoValidate, typeof i2.NgSelectOption, typeof i3.ɵNgSelectMultipleOption, typeof i4.DefaultValueAccessor, typeof i5.NumberValueAccessor, typeof i6.RangeValueAccessor, typeof i7.CheckboxControlValueAccessor, typeof i2.SelectControlValueAccessor, typeof i3.SelectMultipleControlValueAccessor, typeof i8.RadioControlValueAccessor, typeof i9.NgControlStatus, typeof i9.NgControlStatusGroup, typeof i10.RequiredValidator, typeof i10.MinLengthValidator, typeof i10.MaxLengthValidator, typeof i10.PatternValidator, typeof i10.CheckboxRequiredValidator, typeof i10.EmailValidator, typeof i10.MinValidator, typeof i10.MaxValidator]>;
  5145. static ɵinj: i0.ɵɵInjectorDeclaration<ɵInternalFormsSharedModule>;
  5146. }
  5147. declare type ɵIsAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
  5148. /**
  5149. * Navigate takes a type T and an array K, and returns the type of T[K[0]][K[1]][K[2]]...
  5150. */
  5151. export declare type ɵNavigate<T, K extends (Array<string | number>)> = T extends object ? (K extends [infer Head, ...infer Tail] ? (Head extends keyof T ? (Tail extends (string | number)[] ? [
  5152. ] extends Tail ? T[Head] : (ɵNavigate<T[Head], Tail>) : any) : never) : any) : any;
  5153. /**
  5154. * @description
  5155. *
  5156. * Adds `novalidate` attribute to all forms by default.
  5157. *
  5158. * `novalidate` is used to disable browser's native form validation.
  5159. *
  5160. * If you want to use native validation with Angular forms, just add `ngNativeValidate` attribute:
  5161. *
  5162. * ```
  5163. * <form ngNativeValidate></form>
  5164. * ```
  5165. *
  5166. * @publicApi
  5167. * @ngModule ReactiveFormsModule
  5168. * @ngModule FormsModule
  5169. */
  5170. export declare class ɵNgNoValidate {
  5171. static ɵfac: i0.ɵɵFactoryDeclaration<ɵNgNoValidate, never>;
  5172. static ɵdir: i0.ɵɵDirectiveDeclaration<ɵNgNoValidate, "form:not([ngNoForm]):not([ngNativeValidate])", never, {}, {}, never, never, false, never>;
  5173. }
  5174. /**
  5175. * @description
  5176. * Marks `<option>` as dynamic, so Angular can be notified when options change.
  5177. *
  5178. * @see `SelectMultipleControlValueAccessor`
  5179. *
  5180. * @ngModule ReactiveFormsModule
  5181. * @ngModule FormsModule
  5182. * @publicApi
  5183. */
  5184. export declare class ɵNgSelectMultipleOption implements OnDestroy {
  5185. private _element;
  5186. private _renderer;
  5187. private _select;
  5188. id: string;
  5189. constructor(_element: ElementRef, _renderer: Renderer2, _select: SelectMultipleControlValueAccessor);
  5190. /**
  5191. * @description
  5192. * Tracks the value bound to the option element. Unlike the value binding,
  5193. * ngValue supports binding to objects.
  5194. */
  5195. set ngValue(value: any);
  5196. /**
  5197. * @description
  5198. * Tracks simple string values bound to the option element.
  5199. * For objects, use the `ngValue` input binding.
  5200. */
  5201. set value(value: any);
  5202. /** @nodoc */
  5203. ngOnDestroy(): void;
  5204. static ɵfac: i0.ɵɵFactoryDeclaration<ɵNgSelectMultipleOption, [null, null, { optional: true; host: true; }]>;
  5205. static ɵdir: i0.ɵɵDirectiveDeclaration<ɵNgSelectMultipleOption, "option", never, { "ngValue": { "alias": "ngValue"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, {}, never, never, false, never>;
  5206. }
  5207. /**
  5208. * OptionalKeys returns the union of all optional keys in the object.
  5209. *
  5210. * Angular uses this type internally to support Typed Forms; do not use it directly.
  5211. */
  5212. export declare type ɵOptionalKeys<T> = {
  5213. [K in keyof T]-?: undefined extends T[K] ? K : never;
  5214. }[keyof T];
  5215. /**
  5216. * RawValue gives the raw value type corresponding to a control type.
  5217. *
  5218. * Note that the resulting type will follow the same rules as `.getRawValue()` on your control,
  5219. * group, or array. This means that all controls inside a group will be required, not optional,
  5220. * regardless of their disabled state.
  5221. *
  5222. * You may also wish to use {@link ɵValue}, which will have `undefined` in group keys (which can be
  5223. * disabled).
  5224. *
  5225. * @usageNotes
  5226. *
  5227. * ### `FormGroup` raw value type
  5228. *
  5229. * Imagine you have an interface defining the controls in your group. You can extract the shape of
  5230. * the raw values as follows:
  5231. *
  5232. * ```ts
  5233. * interface PartyFormControls {
  5234. * address: FormControl<string>;
  5235. * }
  5236. *
  5237. * // RawValue operates on controls; the object must be wrapped in a FormGroup.
  5238. * type PartyFormValues = RawValue<FormGroup<PartyFormControls>>;
  5239. * ```
  5240. *
  5241. * The resulting type is `{address: string}`. (Note the absence of `undefined`.)
  5242. *
  5243. * **Internal: not for public use.**
  5244. */
  5245. export declare type ɵRawValue<T extends AbstractControl | undefined> = T extends AbstractControl<any, any> ? (T['setValue'] extends ((v: infer R) => void) ? R : never) : never;
  5246. /**
  5247. * Tokenize splits a string literal S by a delimiter D.
  5248. */
  5249. export declare type ɵTokenize<S extends string, D extends string> = string extends S ? string[] : S extends `${infer T}${D}${infer U}` ? [T, ...ɵTokenize<U, D>] : [
  5250. S
  5251. ];
  5252. /**
  5253. * `TypedOrUntyped` allows one of two different types to be selected, depending on whether the Forms
  5254. * class it's applied to is typed or not.
  5255. *
  5256. * This is for internal Angular usage to support typed forms; do not directly use it.
  5257. */
  5258. export declare type ɵTypedOrUntyped<T, Typed, Untyped> = ɵIsAny<T, Untyped, Typed>;
  5259. /**
  5260. * Value gives the value type corresponding to a control type.
  5261. *
  5262. * Note that the resulting type will follow the same rules as `.value` on your control, group, or
  5263. * array, including `undefined` for each group element which might be disabled.
  5264. *
  5265. * If you are trying to extract a value type for a data model, you probably want {@link RawValue},
  5266. * which will not have `undefined` in group keys.
  5267. *
  5268. * @usageNotes
  5269. *
  5270. * ### `FormControl` value type
  5271. *
  5272. * You can extract the value type of a single control:
  5273. *
  5274. * ```ts
  5275. * type NameControl = FormControl<string>;
  5276. * type NameValue = Value<NameControl>;
  5277. * ```
  5278. *
  5279. * The resulting type is `string`.
  5280. *
  5281. * ### `FormGroup` value type
  5282. *
  5283. * Imagine you have an interface defining the controls in your group. You can extract the shape of
  5284. * the values as follows:
  5285. *
  5286. * ```ts
  5287. * interface PartyFormControls {
  5288. * address: FormControl<string>;
  5289. * }
  5290. *
  5291. * // Value operates on controls; the object must be wrapped in a FormGroup.
  5292. * type PartyFormValues = Value<FormGroup<PartyFormControls>>;
  5293. * ```
  5294. *
  5295. * The resulting type is `{address: string|undefined}`.
  5296. *
  5297. * ### `FormArray` value type
  5298. *
  5299. * You can extract values from FormArrays as well:
  5300. *
  5301. * ```ts
  5302. * type GuestNamesControls = FormArray<FormControl<string>>;
  5303. *
  5304. * type NamesValues = Value<GuestNamesControls>;
  5305. * ```
  5306. *
  5307. * The resulting type is `string[]`.
  5308. *
  5309. * **Internal: not for public use.**
  5310. */
  5311. export declare type ɵValue<T extends AbstractControl | undefined> = T extends AbstractControl<any, any> ? T['value'] : never;
  5312. /**
  5313. * ɵWriteable removes readonly from all keys.
  5314. */
  5315. export declare type ɵWriteable<T> = {
  5316. -readonly [P in keyof T]: T[P];
  5317. };
  5318. export { }