index.d.ts 196 KB

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