forms.umd.js 282 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser'), require('rxjs'), require('rxjs/operators')) :
  8. typeof define === 'function' && define.amd ? define('@angular/forms', ['exports', '@angular/core', '@angular/platform-browser', 'rxjs', 'rxjs/operators'], factory) :
  9. (global = global || self, factory((global.ng = global.ng || {}, global.ng.forms = {}), global.ng.core, global.ng.platformBrowser, global.rxjs, global.rxjs.operators));
  10. }(this, function (exports, core, platformBrowser, rxjs, operators) { 'use strict';
  11. /*! *****************************************************************************
  12. Copyright (c) Microsoft Corporation. All rights reserved.
  13. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  14. this file except in compliance with the License. You may obtain a copy of the
  15. License at http://www.apache.org/licenses/LICENSE-2.0
  16. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  18. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  19. MERCHANTABLITY OR NON-INFRINGEMENT.
  20. See the Apache Version 2.0 License for specific language governing permissions
  21. and limitations under the License.
  22. ***************************************************************************** */
  23. /* global Reflect, Promise */
  24. var extendStatics = function(d, b) {
  25. extendStatics = Object.setPrototypeOf ||
  26. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  28. return extendStatics(d, b);
  29. };
  30. function __extends(d, b) {
  31. extendStatics(d, b);
  32. function __() { this.constructor = d; }
  33. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  34. }
  35. var __assign = function() {
  36. __assign = Object.assign || function __assign(t) {
  37. for (var s, i = 1, n = arguments.length; i < n; i++) {
  38. s = arguments[i];
  39. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  40. }
  41. return t;
  42. };
  43. return __assign.apply(this, arguments);
  44. };
  45. function __decorate(decorators, target, key, desc) {
  46. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  47. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  48. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  49. return c > 3 && r && Object.defineProperty(target, key, r), r;
  50. }
  51. function __param(paramIndex, decorator) {
  52. return function (target, key) { decorator(target, key, paramIndex); }
  53. }
  54. function __metadata(metadataKey, metadataValue) {
  55. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  56. }
  57. function __values(o) {
  58. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  59. if (m) return m.call(o);
  60. return {
  61. next: function () {
  62. if (o && i >= o.length) o = void 0;
  63. return { value: o && o[i++], done: !o };
  64. }
  65. };
  66. }
  67. function __read(o, n) {
  68. var m = typeof Symbol === "function" && o[Symbol.iterator];
  69. if (!m) return o;
  70. var i = m.call(o), r, ar = [], e;
  71. try {
  72. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  73. }
  74. catch (error) { e = { error: error }; }
  75. finally {
  76. try {
  77. if (r && !r.done && (m = i["return"])) m.call(i);
  78. }
  79. finally { if (e) throw e.error; }
  80. }
  81. return ar;
  82. }
  83. function __spread() {
  84. for (var ar = [], i = 0; i < arguments.length; i++)
  85. ar = ar.concat(__read(arguments[i]));
  86. return ar;
  87. }
  88. /**
  89. * @license
  90. * Copyright Google Inc. All Rights Reserved.
  91. *
  92. * Use of this source code is governed by an MIT-style license that can be
  93. * found in the LICENSE file at https://angular.io/license
  94. */
  95. /**
  96. * Used to provide a `ControlValueAccessor` for form controls.
  97. *
  98. * See `DefaultValueAccessor` for how to implement one.
  99. *
  100. * @publicApi
  101. */
  102. var NG_VALUE_ACCESSOR = new core.InjectionToken('NgValueAccessor');
  103. /**
  104. * @license
  105. * Copyright Google Inc. All Rights Reserved.
  106. *
  107. * Use of this source code is governed by an MIT-style license that can be
  108. * found in the LICENSE file at https://angular.io/license
  109. */
  110. var CHECKBOX_VALUE_ACCESSOR = {
  111. provide: NG_VALUE_ACCESSOR,
  112. useExisting: core.forwardRef(function () { return CheckboxControlValueAccessor; }),
  113. multi: true,
  114. };
  115. /**
  116. * @description
  117. * A `ControlValueAccessor` for writing a value and listening to changes on a checkbox input
  118. * element.
  119. *
  120. * @usageNotes
  121. *
  122. * ### Using a checkbox with a reactive form.
  123. *
  124. * The following example shows how to use a checkbox with a reactive form.
  125. *
  126. * ```ts
  127. * const rememberLoginControl = new FormControl();
  128. * ```
  129. *
  130. * ```
  131. * <input type="checkbox" [formControl]="rememberLoginControl">
  132. * ```
  133. *
  134. * @ngModule ReactiveFormsModule
  135. * @ngModule FormsModule
  136. * @publicApi
  137. */
  138. var CheckboxControlValueAccessor = /** @class */ (function () {
  139. function CheckboxControlValueAccessor(_renderer, _elementRef) {
  140. this._renderer = _renderer;
  141. this._elementRef = _elementRef;
  142. /**
  143. * @description
  144. * The registered callback function called when a change event occurs on the input element.
  145. */
  146. this.onChange = function (_) { };
  147. /**
  148. * @description
  149. * The registered callback function called when a blur event occurs on the input element.
  150. */
  151. this.onTouched = function () { };
  152. }
  153. /**
  154. * Sets the "checked" property on the input element.
  155. *
  156. * @param value The checked value
  157. */
  158. CheckboxControlValueAccessor.prototype.writeValue = function (value) {
  159. this._renderer.setProperty(this._elementRef.nativeElement, 'checked', value);
  160. };
  161. /**
  162. * @description
  163. * Registers a function called when the control value changes.
  164. *
  165. * @param fn The callback function
  166. */
  167. CheckboxControlValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; };
  168. /**
  169. * @description
  170. * Registers a function called when the control is touched.
  171. *
  172. * @param fn The callback function
  173. */
  174. CheckboxControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  175. /**
  176. * Sets the "disabled" property on the input element.
  177. *
  178. * @param isDisabled The disabled value
  179. */
  180. CheckboxControlValueAccessor.prototype.setDisabledState = function (isDisabled) {
  181. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  182. };
  183. CheckboxControlValueAccessor = __decorate([
  184. core.Directive({
  185. selector: 'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
  186. host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' },
  187. providers: [CHECKBOX_VALUE_ACCESSOR]
  188. }),
  189. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef])
  190. ], CheckboxControlValueAccessor);
  191. return CheckboxControlValueAccessor;
  192. }());
  193. /**
  194. * @license
  195. * Copyright Google Inc. All Rights Reserved.
  196. *
  197. * Use of this source code is governed by an MIT-style license that can be
  198. * found in the LICENSE file at https://angular.io/license
  199. */
  200. var DEFAULT_VALUE_ACCESSOR = {
  201. provide: NG_VALUE_ACCESSOR,
  202. useExisting: core.forwardRef(function () { return DefaultValueAccessor; }),
  203. multi: true
  204. };
  205. /**
  206. * We must check whether the agent is Android because composition events
  207. * behave differently between iOS and Android.
  208. */
  209. function _isAndroid() {
  210. var userAgent = platformBrowser.ɵgetDOM() ? platformBrowser.ɵgetDOM().getUserAgent() : '';
  211. return /android (\d+)/.test(userAgent.toLowerCase());
  212. }
  213. /**
  214. * @description
  215. * Provide this token to control if form directives buffer IME input until
  216. * the "compositionend" event occurs.
  217. * @publicApi
  218. */
  219. var COMPOSITION_BUFFER_MODE = new core.InjectionToken('CompositionEventMode');
  220. /**
  221. * @description
  222. * The default `ControlValueAccessor` for writing a value and listening to changes on input
  223. * elements. The accessor is used by the `FormControlDirective`, `FormControlName`, and
  224. * `NgModel` directives.
  225. *
  226. * @usageNotes
  227. *
  228. * ### Using the default value accessor
  229. *
  230. * The following example shows how to use an input element that activates the default value accessor
  231. * (in this case, a text field).
  232. *
  233. * ```ts
  234. * const firstNameControl = new FormControl();
  235. * ```
  236. *
  237. * ```
  238. * <input type="text" [formControl]="firstNameControl">
  239. * ```
  240. *
  241. * @ngModule ReactiveFormsModule
  242. * @ngModule FormsModule
  243. * @publicApi
  244. */
  245. var DefaultValueAccessor = /** @class */ (function () {
  246. function DefaultValueAccessor(_renderer, _elementRef, _compositionMode) {
  247. this._renderer = _renderer;
  248. this._elementRef = _elementRef;
  249. this._compositionMode = _compositionMode;
  250. /**
  251. * @description
  252. * The registered callback function called when an input event occurs on the input element.
  253. */
  254. this.onChange = function (_) { };
  255. /**
  256. * @description
  257. * The registered callback function called when a blur event occurs on the input element.
  258. */
  259. this.onTouched = function () { };
  260. /** Whether the user is creating a composition string (IME events). */
  261. this._composing = false;
  262. if (this._compositionMode == null) {
  263. this._compositionMode = !_isAndroid();
  264. }
  265. }
  266. /**
  267. * Sets the "value" property on the input element.
  268. *
  269. * @param value The checked value
  270. */
  271. DefaultValueAccessor.prototype.writeValue = function (value) {
  272. var normalizedValue = value == null ? '' : value;
  273. this._renderer.setProperty(this._elementRef.nativeElement, 'value', normalizedValue);
  274. };
  275. /**
  276. * @description
  277. * Registers a function called when the control value changes.
  278. *
  279. * @param fn The callback function
  280. */
  281. DefaultValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; };
  282. /**
  283. * @description
  284. * Registers a function called when the control is touched.
  285. *
  286. * @param fn The callback function
  287. */
  288. DefaultValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  289. /**
  290. * Sets the "disabled" property on the input element.
  291. *
  292. * @param isDisabled The disabled value
  293. */
  294. DefaultValueAccessor.prototype.setDisabledState = function (isDisabled) {
  295. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  296. };
  297. /** @internal */
  298. DefaultValueAccessor.prototype._handleInput = function (value) {
  299. if (!this._compositionMode || (this._compositionMode && !this._composing)) {
  300. this.onChange(value);
  301. }
  302. };
  303. /** @internal */
  304. DefaultValueAccessor.prototype._compositionStart = function () { this._composing = true; };
  305. /** @internal */
  306. DefaultValueAccessor.prototype._compositionEnd = function (value) {
  307. this._composing = false;
  308. this._compositionMode && this.onChange(value);
  309. };
  310. DefaultValueAccessor = __decorate([
  311. core.Directive({
  312. selector: 'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
  313. // TODO: vsavkin replace the above selector with the one below it once
  314. // https://github.com/angular/angular/issues/3011 is implemented
  315. // selector: '[ngModel],[formControl],[formControlName]',
  316. host: {
  317. '(input)': '$any(this)._handleInput($event.target.value)',
  318. '(blur)': 'onTouched()',
  319. '(compositionstart)': '$any(this)._compositionStart()',
  320. '(compositionend)': '$any(this)._compositionEnd($event.target.value)'
  321. },
  322. providers: [DEFAULT_VALUE_ACCESSOR]
  323. }),
  324. __param(2, core.Optional()), __param(2, core.Inject(COMPOSITION_BUFFER_MODE)),
  325. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef, Boolean])
  326. ], DefaultValueAccessor);
  327. return DefaultValueAccessor;
  328. }());
  329. /**
  330. * @license
  331. * Copyright Google Inc. All Rights Reserved.
  332. *
  333. * Use of this source code is governed by an MIT-style license that can be
  334. * found in the LICENSE file at https://angular.io/license
  335. */
  336. /**
  337. * @description
  338. * Base class for control directives.
  339. *
  340. * This class is only used internally in the `ReactiveFormsModule` and the `FormsModule`.
  341. *
  342. * @publicApi
  343. */
  344. var AbstractControlDirective = /** @class */ (function () {
  345. function AbstractControlDirective() {
  346. }
  347. Object.defineProperty(AbstractControlDirective.prototype, "value", {
  348. /**
  349. * @description
  350. * Reports the value of the control if it is present, otherwise null.
  351. */
  352. get: function () { return this.control ? this.control.value : null; },
  353. enumerable: true,
  354. configurable: true
  355. });
  356. Object.defineProperty(AbstractControlDirective.prototype, "valid", {
  357. /**
  358. * @description
  359. * Reports whether the control is valid. A control is considered valid if no
  360. * validation errors exist with the current value.
  361. * If the control is not present, null is returned.
  362. */
  363. get: function () { return this.control ? this.control.valid : null; },
  364. enumerable: true,
  365. configurable: true
  366. });
  367. Object.defineProperty(AbstractControlDirective.prototype, "invalid", {
  368. /**
  369. * @description
  370. * Reports whether the control is invalid, meaning that an error exists in the input value.
  371. * If the control is not present, null is returned.
  372. */
  373. get: function () { return this.control ? this.control.invalid : null; },
  374. enumerable: true,
  375. configurable: true
  376. });
  377. Object.defineProperty(AbstractControlDirective.prototype, "pending", {
  378. /**
  379. * @description
  380. * Reports whether a control is pending, meaning that that async validation is occurring and
  381. * errors are not yet available for the input value. If the control is not present, null is
  382. * returned.
  383. */
  384. get: function () { return this.control ? this.control.pending : null; },
  385. enumerable: true,
  386. configurable: true
  387. });
  388. Object.defineProperty(AbstractControlDirective.prototype, "disabled", {
  389. /**
  390. * @description
  391. * Reports whether the control is disabled, meaning that the control is disabled
  392. * in the UI and is exempt from validation checks and excluded from aggregate
  393. * values of ancestor controls. If the control is not present, null is returned.
  394. */
  395. get: function () { return this.control ? this.control.disabled : null; },
  396. enumerable: true,
  397. configurable: true
  398. });
  399. Object.defineProperty(AbstractControlDirective.prototype, "enabled", {
  400. /**
  401. * @description
  402. * Reports whether the control is enabled, meaning that the control is included in ancestor
  403. * calculations of validity or value. If the control is not present, null is returned.
  404. */
  405. get: function () { return this.control ? this.control.enabled : null; },
  406. enumerable: true,
  407. configurable: true
  408. });
  409. Object.defineProperty(AbstractControlDirective.prototype, "errors", {
  410. /**
  411. * @description
  412. * Reports the control's validation errors. If the control is not present, null is returned.
  413. */
  414. get: function () { return this.control ? this.control.errors : null; },
  415. enumerable: true,
  416. configurable: true
  417. });
  418. Object.defineProperty(AbstractControlDirective.prototype, "pristine", {
  419. /**
  420. * @description
  421. * Reports whether the control is pristine, meaning that the user has not yet changed
  422. * the value in the UI. If the control is not present, null is returned.
  423. */
  424. get: function () { return this.control ? this.control.pristine : null; },
  425. enumerable: true,
  426. configurable: true
  427. });
  428. Object.defineProperty(AbstractControlDirective.prototype, "dirty", {
  429. /**
  430. * @description
  431. * Reports whether the control is dirty, meaning that the user has changed
  432. * the value in the UI. If the control is not present, null is returned.
  433. */
  434. get: function () { return this.control ? this.control.dirty : null; },
  435. enumerable: true,
  436. configurable: true
  437. });
  438. Object.defineProperty(AbstractControlDirective.prototype, "touched", {
  439. /**
  440. * @description
  441. * Reports whether the control is touched, meaning that the user has triggered
  442. * a `blur` event on it. If the control is not present, null is returned.
  443. */
  444. get: function () { return this.control ? this.control.touched : null; },
  445. enumerable: true,
  446. configurable: true
  447. });
  448. Object.defineProperty(AbstractControlDirective.prototype, "status", {
  449. /**
  450. * @description
  451. * Reports the validation status of the control. Possible values include:
  452. * 'VALID', 'INVALID', 'DISABLED', and 'PENDING'.
  453. * If the control is not present, null is returned.
  454. */
  455. get: function () { return this.control ? this.control.status : null; },
  456. enumerable: true,
  457. configurable: true
  458. });
  459. Object.defineProperty(AbstractControlDirective.prototype, "untouched", {
  460. /**
  461. * @description
  462. * Reports whether the control is untouched, meaning that the user has not yet triggered
  463. * a `blur` event on it. If the control is not present, null is returned.
  464. */
  465. get: function () { return this.control ? this.control.untouched : null; },
  466. enumerable: true,
  467. configurable: true
  468. });
  469. Object.defineProperty(AbstractControlDirective.prototype, "statusChanges", {
  470. /**
  471. * @description
  472. * Returns a multicasting observable that emits a validation status whenever it is
  473. * calculated for the control. If the control is not present, null is returned.
  474. */
  475. get: function () {
  476. return this.control ? this.control.statusChanges : null;
  477. },
  478. enumerable: true,
  479. configurable: true
  480. });
  481. Object.defineProperty(AbstractControlDirective.prototype, "valueChanges", {
  482. /**
  483. * @description
  484. * Returns a multicasting observable of value changes for the control that emits every time the
  485. * value of the control changes in the UI or programmatically.
  486. * If the control is not present, null is returned.
  487. */
  488. get: function () {
  489. return this.control ? this.control.valueChanges : null;
  490. },
  491. enumerable: true,
  492. configurable: true
  493. });
  494. Object.defineProperty(AbstractControlDirective.prototype, "path", {
  495. /**
  496. * @description
  497. * Returns an array that represents the path from the top-level form to this control.
  498. * Each index is the string name of the control on that level.
  499. */
  500. get: function () { return null; },
  501. enumerable: true,
  502. configurable: true
  503. });
  504. /**
  505. * @description
  506. * Resets the control with the provided value if the control is present.
  507. */
  508. AbstractControlDirective.prototype.reset = function (value) {
  509. if (value === void 0) { value = undefined; }
  510. if (this.control)
  511. this.control.reset(value);
  512. };
  513. /**
  514. * @description
  515. * Reports whether the control with the given path has the error specified.
  516. *
  517. * @param errorCode The code of the error to check
  518. * @param path A list of control names that designates how to move from the current control
  519. * to the control that should be queried for errors.
  520. *
  521. * @usageNotes
  522. * For example, for the following `FormGroup`:
  523. *
  524. * ```
  525. * form = new FormGroup({
  526. * address: new FormGroup({ street: new FormControl() })
  527. * });
  528. * ```
  529. *
  530. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  531. *
  532. * It can be provided to this method in one of two formats:
  533. *
  534. * 1. An array of string control names, e.g. `['address', 'street']`
  535. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  536. *
  537. * If no path is given, this method checks for the error on the current control.
  538. *
  539. * @returns whether the given error is present in the control at the given path.
  540. *
  541. * If the control is not present, false is returned.
  542. */
  543. AbstractControlDirective.prototype.hasError = function (errorCode, path) {
  544. return this.control ? this.control.hasError(errorCode, path) : false;
  545. };
  546. /**
  547. * @description
  548. * Reports error data for the control with the given path.
  549. *
  550. * @param errorCode The code of the error to check
  551. * @param path A list of control names that designates how to move from the current control
  552. * to the control that should be queried for errors.
  553. *
  554. * @usageNotes
  555. * For example, for the following `FormGroup`:
  556. *
  557. * ```
  558. * form = new FormGroup({
  559. * address: new FormGroup({ street: new FormControl() })
  560. * });
  561. * ```
  562. *
  563. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  564. *
  565. * It can be provided to this method in one of two formats:
  566. *
  567. * 1. An array of string control names, e.g. `['address', 'street']`
  568. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  569. *
  570. * @returns error data for that particular error. If the control or error is not present,
  571. * null is returned.
  572. */
  573. AbstractControlDirective.prototype.getError = function (errorCode, path) {
  574. return this.control ? this.control.getError(errorCode, path) : null;
  575. };
  576. return AbstractControlDirective;
  577. }());
  578. /**
  579. * @license
  580. * Copyright Google Inc. All Rights Reserved.
  581. *
  582. * Use of this source code is governed by an MIT-style license that can be
  583. * found in the LICENSE file at https://angular.io/license
  584. */
  585. /**
  586. * @description
  587. * A base class for directives that contain multiple registered instances of `NgControl`.
  588. * Only used by the forms module.
  589. *
  590. * @publicApi
  591. */
  592. var ControlContainer = /** @class */ (function (_super) {
  593. __extends(ControlContainer, _super);
  594. function ControlContainer() {
  595. return _super !== null && _super.apply(this, arguments) || this;
  596. }
  597. Object.defineProperty(ControlContainer.prototype, "formDirective", {
  598. /**
  599. * @description
  600. * The top-level form directive for the control.
  601. */
  602. get: function () { return null; },
  603. enumerable: true,
  604. configurable: true
  605. });
  606. Object.defineProperty(ControlContainer.prototype, "path", {
  607. /**
  608. * @description
  609. * The path to this group.
  610. */
  611. get: function () { return null; },
  612. enumerable: true,
  613. configurable: true
  614. });
  615. return ControlContainer;
  616. }(AbstractControlDirective));
  617. /**
  618. * @license
  619. * Copyright Google Inc. All Rights Reserved.
  620. *
  621. * Use of this source code is governed by an MIT-style license that can be
  622. * found in the LICENSE file at https://angular.io/license
  623. */
  624. function unimplemented() {
  625. throw new Error('unimplemented');
  626. }
  627. /**
  628. * @description
  629. * A base class that all control `FormControl`-based directives extend. It binds a `FormControl`
  630. * object to a DOM element.
  631. *
  632. * @publicApi
  633. */
  634. var NgControl = /** @class */ (function (_super) {
  635. __extends(NgControl, _super);
  636. function NgControl() {
  637. var _this = _super !== null && _super.apply(this, arguments) || this;
  638. /**
  639. * @description
  640. * The parent form for the control.
  641. *
  642. * @internal
  643. */
  644. _this._parent = null;
  645. /**
  646. * @description
  647. * The name for the control
  648. */
  649. _this.name = null;
  650. /**
  651. * @description
  652. * The value accessor for the control
  653. */
  654. _this.valueAccessor = null;
  655. /**
  656. * @description
  657. * The uncomposed array of synchronous validators for the control
  658. *
  659. * @internal
  660. */
  661. _this._rawValidators = [];
  662. /**
  663. * @description
  664. * The uncomposed array of async validators for the control
  665. *
  666. * @internal
  667. */
  668. _this._rawAsyncValidators = [];
  669. return _this;
  670. }
  671. Object.defineProperty(NgControl.prototype, "validator", {
  672. /**
  673. * @description
  674. * The registered synchronous validator function for the control
  675. *
  676. * @throws An exception that this method is not implemented
  677. */
  678. get: function () { return unimplemented(); },
  679. enumerable: true,
  680. configurable: true
  681. });
  682. Object.defineProperty(NgControl.prototype, "asyncValidator", {
  683. /**
  684. * @description
  685. * The registered async validator function for the control
  686. *
  687. * @throws An exception that this method is not implemented
  688. */
  689. get: function () { return unimplemented(); },
  690. enumerable: true,
  691. configurable: true
  692. });
  693. return NgControl;
  694. }(AbstractControlDirective));
  695. /**
  696. * @license
  697. * Copyright Google Inc. All Rights Reserved.
  698. *
  699. * Use of this source code is governed by an MIT-style license that can be
  700. * found in the LICENSE file at https://angular.io/license
  701. */
  702. var AbstractControlStatus = /** @class */ (function () {
  703. function AbstractControlStatus(cd) {
  704. this._cd = cd;
  705. }
  706. Object.defineProperty(AbstractControlStatus.prototype, "ngClassUntouched", {
  707. get: function () { return this._cd.control ? this._cd.control.untouched : false; },
  708. enumerable: true,
  709. configurable: true
  710. });
  711. Object.defineProperty(AbstractControlStatus.prototype, "ngClassTouched", {
  712. get: function () { return this._cd.control ? this._cd.control.touched : false; },
  713. enumerable: true,
  714. configurable: true
  715. });
  716. Object.defineProperty(AbstractControlStatus.prototype, "ngClassPristine", {
  717. get: function () { return this._cd.control ? this._cd.control.pristine : false; },
  718. enumerable: true,
  719. configurable: true
  720. });
  721. Object.defineProperty(AbstractControlStatus.prototype, "ngClassDirty", {
  722. get: function () { return this._cd.control ? this._cd.control.dirty : false; },
  723. enumerable: true,
  724. configurable: true
  725. });
  726. Object.defineProperty(AbstractControlStatus.prototype, "ngClassValid", {
  727. get: function () { return this._cd.control ? this._cd.control.valid : false; },
  728. enumerable: true,
  729. configurable: true
  730. });
  731. Object.defineProperty(AbstractControlStatus.prototype, "ngClassInvalid", {
  732. get: function () { return this._cd.control ? this._cd.control.invalid : false; },
  733. enumerable: true,
  734. configurable: true
  735. });
  736. Object.defineProperty(AbstractControlStatus.prototype, "ngClassPending", {
  737. get: function () { return this._cd.control ? this._cd.control.pending : false; },
  738. enumerable: true,
  739. configurable: true
  740. });
  741. return AbstractControlStatus;
  742. }());
  743. var ngControlStatusHost = {
  744. '[class.ng-untouched]': 'ngClassUntouched',
  745. '[class.ng-touched]': 'ngClassTouched',
  746. '[class.ng-pristine]': 'ngClassPristine',
  747. '[class.ng-dirty]': 'ngClassDirty',
  748. '[class.ng-valid]': 'ngClassValid',
  749. '[class.ng-invalid]': 'ngClassInvalid',
  750. '[class.ng-pending]': 'ngClassPending',
  751. };
  752. /**
  753. * @description
  754. * Directive automatically applied to Angular form controls that sets CSS classes
  755. * based on control status.
  756. *
  757. * @usageNotes
  758. *
  759. * ### CSS classes applied
  760. *
  761. * The following classes are applied as the properties become true:
  762. *
  763. * * ng-valid
  764. * * ng-invalid
  765. * * ng-pending
  766. * * ng-pristine
  767. * * ng-dirty
  768. * * ng-untouched
  769. * * ng-touched
  770. *
  771. * @ngModule ReactiveFormsModule
  772. * @ngModule FormsModule
  773. * @publicApi
  774. */
  775. var NgControlStatus = /** @class */ (function (_super) {
  776. __extends(NgControlStatus, _super);
  777. function NgControlStatus(cd) {
  778. return _super.call(this, cd) || this;
  779. }
  780. NgControlStatus = __decorate([
  781. core.Directive({ selector: '[formControlName],[ngModel],[formControl]', host: ngControlStatusHost }),
  782. __param(0, core.Self()),
  783. __metadata("design:paramtypes", [NgControl])
  784. ], NgControlStatus);
  785. return NgControlStatus;
  786. }(AbstractControlStatus));
  787. /**
  788. * @description
  789. * Directive automatically applied to Angular form groups that sets CSS classes
  790. * based on control status (valid/invalid/dirty/etc).
  791. *
  792. * @see `NgControlStatus`
  793. *
  794. * @ngModule ReactiveFormsModule
  795. * @ngModule FormsModule
  796. * @publicApi
  797. */
  798. var NgControlStatusGroup = /** @class */ (function (_super) {
  799. __extends(NgControlStatusGroup, _super);
  800. function NgControlStatusGroup(cd) {
  801. return _super.call(this, cd) || this;
  802. }
  803. NgControlStatusGroup = __decorate([
  804. core.Directive({
  805. selector: '[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]',
  806. host: ngControlStatusHost
  807. }),
  808. __param(0, core.Self()),
  809. __metadata("design:paramtypes", [ControlContainer])
  810. ], NgControlStatusGroup);
  811. return NgControlStatusGroup;
  812. }(AbstractControlStatus));
  813. /**
  814. * @license
  815. * Copyright Google Inc. All Rights Reserved.
  816. *
  817. * Use of this source code is governed by an MIT-style license that can be
  818. * found in the LICENSE file at https://angular.io/license
  819. */
  820. function isEmptyInputValue(value) {
  821. // we don't check for string here so it also works with arrays
  822. return value == null || value.length === 0;
  823. }
  824. /**
  825. * @description
  826. * An `InjectionToken` for registering additional synchronous validators used with `AbstractControl`s.
  827. *
  828. * @see `NG_ASYNC_VALIDATORS`
  829. *
  830. * @usageNotes
  831. *
  832. * ### Providing a custom validator
  833. *
  834. * The following example registers a custom validator directive. Adding the validator to the
  835. * existing collection of validators requires the `multi: true` option.
  836. *
  837. * ```typescript
  838. * @Directive({
  839. * selector: '[customValidator]',
  840. * providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
  841. * })
  842. * class CustomValidatorDirective implements Validator {
  843. * validate(control: AbstractControl): ValidationErrors | null {
  844. * return { 'custom': true };
  845. * }
  846. * }
  847. * ```
  848. *
  849. * @publicApi
  850. */
  851. var NG_VALIDATORS = new core.InjectionToken('NgValidators');
  852. /**
  853. * @description
  854. * An `InjectionToken` for registering additional asynchronous validators used with `AbstractControl`s.
  855. *
  856. * @see `NG_VALIDATORS`
  857. *
  858. * @publicApi
  859. */
  860. var NG_ASYNC_VALIDATORS = new core.InjectionToken('NgAsyncValidators');
  861. var EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
  862. /**
  863. * @description
  864. * Provides a set of built-in validators that can be used by form controls.
  865. *
  866. * A validator is a function that processes a `FormControl` or collection of
  867. * controls and returns an error map or null. A null map means that validation has passed.
  868. *
  869. * @see [Form Validation](/guide/form-validation)
  870. *
  871. * @publicApi
  872. */
  873. var Validators = /** @class */ (function () {
  874. function Validators() {
  875. }
  876. /**
  877. * @description
  878. * Validator that requires the control's value to be greater than or equal to the provided number.
  879. * The validator exists only as a function and not as a directive.
  880. *
  881. * @usageNotes
  882. *
  883. * ### Validate against a minimum of 3
  884. *
  885. * ```typescript
  886. * const control = new FormControl(2, Validators.min(3));
  887. *
  888. * console.log(control.errors); // {min: {min: 3, actual: 2}}
  889. * ```
  890. *
  891. * @returns A validator function that returns an error map with the
  892. * `min` property if the validation check fails, otherwise `null`.
  893. *
  894. */
  895. Validators.min = function (min) {
  896. return function (control) {
  897. if (isEmptyInputValue(control.value) || isEmptyInputValue(min)) {
  898. return null; // don't validate empty values to allow optional controls
  899. }
  900. var value = parseFloat(control.value);
  901. // Controls with NaN values after parsing should be treated as not having a
  902. // minimum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-min
  903. return !isNaN(value) && value < min ? { 'min': { 'min': min, 'actual': control.value } } : null;
  904. };
  905. };
  906. /**
  907. * @description
  908. * Validator that requires the control's value to be less than or equal to the provided number.
  909. * The validator exists only as a function and not as a directive.
  910. *
  911. * @usageNotes
  912. *
  913. * ### Validate against a maximum of 15
  914. *
  915. * ```typescript
  916. * const control = new FormControl(16, Validators.max(15));
  917. *
  918. * console.log(control.errors); // {max: {max: 15, actual: 16}}
  919. * ```
  920. *
  921. * @returns A validator function that returns an error map with the
  922. * `max` property if the validation check fails, otherwise `null`.
  923. *
  924. */
  925. Validators.max = function (max) {
  926. return function (control) {
  927. if (isEmptyInputValue(control.value) || isEmptyInputValue(max)) {
  928. return null; // don't validate empty values to allow optional controls
  929. }
  930. var value = parseFloat(control.value);
  931. // Controls with NaN values after parsing should be treated as not having a
  932. // maximum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-max
  933. return !isNaN(value) && value > max ? { 'max': { 'max': max, 'actual': control.value } } : null;
  934. };
  935. };
  936. /**
  937. * @description
  938. * Validator that requires the control have a non-empty value.
  939. *
  940. * @usageNotes
  941. *
  942. * ### Validate that the field is non-empty
  943. *
  944. * ```typescript
  945. * const control = new FormControl('', Validators.required);
  946. *
  947. * console.log(control.errors); // {required: true}
  948. * ```
  949. *
  950. * @returns An error map with the `required` property
  951. * if the validation check fails, otherwise `null`.
  952. *
  953. */
  954. Validators.required = function (control) {
  955. return isEmptyInputValue(control.value) ? { 'required': true } : null;
  956. };
  957. /**
  958. * @description
  959. * Validator that requires the control's value be true. This validator is commonly
  960. * used for required checkboxes.
  961. *
  962. * @usageNotes
  963. *
  964. * ### Validate that the field value is true
  965. *
  966. * ```typescript
  967. * const control = new FormControl('', Validators.requiredTrue);
  968. *
  969. * console.log(control.errors); // {required: true}
  970. * ```
  971. *
  972. * @returns An error map that contains the `required` property
  973. * set to `true` if the validation check fails, otherwise `null`.
  974. */
  975. Validators.requiredTrue = function (control) {
  976. return control.value === true ? null : { 'required': true };
  977. };
  978. /**
  979. * @description
  980. * Validator that requires the control's value pass an email validation test.
  981. *
  982. * @usageNotes
  983. *
  984. * ### Validate that the field matches a valid email pattern
  985. *
  986. * ```typescript
  987. * const control = new FormControl('bad@', Validators.email);
  988. *
  989. * console.log(control.errors); // {email: true}
  990. * ```
  991. *
  992. * @returns An error map with the `email` property
  993. * if the validation check fails, otherwise `null`.
  994. *
  995. */
  996. Validators.email = function (control) {
  997. if (isEmptyInputValue(control.value)) {
  998. return null; // don't validate empty values to allow optional controls
  999. }
  1000. return EMAIL_REGEXP.test(control.value) ? null : { 'email': true };
  1001. };
  1002. /**
  1003. * @description
  1004. * Validator that requires the length of the control's value to be greater than or equal
  1005. * to the provided minimum length. This validator is also provided by default if you use the
  1006. * the HTML5 `minlength` attribute.
  1007. *
  1008. * @usageNotes
  1009. *
  1010. * ### Validate that the field has a minimum of 3 characters
  1011. *
  1012. * ```typescript
  1013. * const control = new FormControl('ng', Validators.minLength(3));
  1014. *
  1015. * console.log(control.errors); // {minlength: {requiredLength: 3, actualLength: 2}}
  1016. * ```
  1017. *
  1018. * ```html
  1019. * <input minlength="5">
  1020. * ```
  1021. *
  1022. * @returns A validator function that returns an error map with the
  1023. * `minlength` if the validation check fails, otherwise `null`.
  1024. */
  1025. Validators.minLength = function (minLength) {
  1026. return function (control) {
  1027. if (isEmptyInputValue(control.value)) {
  1028. return null; // don't validate empty values to allow optional controls
  1029. }
  1030. var length = control.value ? control.value.length : 0;
  1031. return length < minLength ?
  1032. { 'minlength': { 'requiredLength': minLength, 'actualLength': length } } :
  1033. null;
  1034. };
  1035. };
  1036. /**
  1037. * @description
  1038. * Validator that requires the length of the control's value to be less than or equal
  1039. * to the provided maximum length. This validator is also provided by default if you use the
  1040. * the HTML5 `maxlength` attribute.
  1041. *
  1042. * @usageNotes
  1043. *
  1044. * ### Validate that the field has maximum of 5 characters
  1045. *
  1046. * ```typescript
  1047. * const control = new FormControl('Angular', Validators.maxLength(5));
  1048. *
  1049. * console.log(control.errors); // {maxlength: {requiredLength: 5, actualLength: 7}}
  1050. * ```
  1051. *
  1052. * ```html
  1053. * <input maxlength="5">
  1054. * ```
  1055. *
  1056. * @returns A validator function that returns an error map with the
  1057. * `maxlength` property if the validation check fails, otherwise `null`.
  1058. */
  1059. Validators.maxLength = function (maxLength) {
  1060. return function (control) {
  1061. var length = control.value ? control.value.length : 0;
  1062. return length > maxLength ?
  1063. { 'maxlength': { 'requiredLength': maxLength, 'actualLength': length } } :
  1064. null;
  1065. };
  1066. };
  1067. /**
  1068. * @description
  1069. * Validator that requires the control's value to match a regex pattern. This validator is also
  1070. * provided by default if you use the HTML5 `pattern` attribute.
  1071. *
  1072. * Note that if a Regexp is provided, the Regexp is used as is to test the values. On the other
  1073. * hand, if a string is passed, the `^` character is prepended and the `$` character is
  1074. * appended to the provided string (if not already present), and the resulting regular
  1075. * expression is used to test the values.
  1076. *
  1077. * @usageNotes
  1078. *
  1079. * ### Validate that the field only contains letters or spaces
  1080. *
  1081. * ```typescript
  1082. * const control = new FormControl('1', Validators.pattern('[a-zA-Z ]*'));
  1083. *
  1084. * console.log(control.errors); // {pattern: {requiredPattern: '^[a-zA-Z ]*$', actualValue: '1'}}
  1085. * ```
  1086. *
  1087. * ```html
  1088. * <input pattern="[a-zA-Z ]*">
  1089. * ```
  1090. *
  1091. * @returns A validator function that returns an error map with the
  1092. * `pattern` property if the validation check fails, otherwise `null`.
  1093. */
  1094. Validators.pattern = function (pattern) {
  1095. if (!pattern)
  1096. return Validators.nullValidator;
  1097. var regex;
  1098. var regexStr;
  1099. if (typeof pattern === 'string') {
  1100. regexStr = '';
  1101. if (pattern.charAt(0) !== '^')
  1102. regexStr += '^';
  1103. regexStr += pattern;
  1104. if (pattern.charAt(pattern.length - 1) !== '$')
  1105. regexStr += '$';
  1106. regex = new RegExp(regexStr);
  1107. }
  1108. else {
  1109. regexStr = pattern.toString();
  1110. regex = pattern;
  1111. }
  1112. return function (control) {
  1113. if (isEmptyInputValue(control.value)) {
  1114. return null; // don't validate empty values to allow optional controls
  1115. }
  1116. var value = control.value;
  1117. return regex.test(value) ? null :
  1118. { 'pattern': { 'requiredPattern': regexStr, 'actualValue': value } };
  1119. };
  1120. };
  1121. /**
  1122. * @description
  1123. * Validator that performs no operation.
  1124. */
  1125. Validators.nullValidator = function (control) { return null; };
  1126. Validators.compose = function (validators) {
  1127. if (!validators)
  1128. return null;
  1129. var presentValidators = validators.filter(isPresent);
  1130. if (presentValidators.length == 0)
  1131. return null;
  1132. return function (control) {
  1133. return _mergeErrors(_executeValidators(control, presentValidators));
  1134. };
  1135. };
  1136. /**
  1137. * @description
  1138. * Compose multiple async validators into a single function that returns the union
  1139. * of the individual error objects for the provided control.
  1140. *
  1141. * @returns A validator function that returns an error map with the
  1142. * merged error objects of the async validators if the validation check fails, otherwise `null`.
  1143. */
  1144. Validators.composeAsync = function (validators) {
  1145. if (!validators)
  1146. return null;
  1147. var presentValidators = validators.filter(isPresent);
  1148. if (presentValidators.length == 0)
  1149. return null;
  1150. return function (control) {
  1151. var observables = _executeAsyncValidators(control, presentValidators).map(toObservable);
  1152. return rxjs.forkJoin(observables).pipe(operators.map(_mergeErrors));
  1153. };
  1154. };
  1155. return Validators;
  1156. }());
  1157. function isPresent(o) {
  1158. return o != null;
  1159. }
  1160. function toObservable(r) {
  1161. var obs = core.ɵisPromise(r) ? rxjs.from(r) : r;
  1162. if (!(core.ɵisObservable(obs))) {
  1163. throw new Error("Expected validator to return Promise or Observable.");
  1164. }
  1165. return obs;
  1166. }
  1167. function _executeValidators(control, validators) {
  1168. return validators.map(function (v) { return v(control); });
  1169. }
  1170. function _executeAsyncValidators(control, validators) {
  1171. return validators.map(function (v) { return v(control); });
  1172. }
  1173. function _mergeErrors(arrayOfErrors) {
  1174. var res = arrayOfErrors.reduce(function (res, errors) {
  1175. return errors != null ? __assign({}, res, errors) : res;
  1176. }, {});
  1177. return Object.keys(res).length === 0 ? null : res;
  1178. }
  1179. /**
  1180. * @license
  1181. * Copyright Google Inc. All Rights Reserved.
  1182. *
  1183. * Use of this source code is governed by an MIT-style license that can be
  1184. * found in the LICENSE file at https://angular.io/license
  1185. */
  1186. function normalizeValidator(validator) {
  1187. if (validator.validate) {
  1188. return function (c) { return validator.validate(c); };
  1189. }
  1190. else {
  1191. return validator;
  1192. }
  1193. }
  1194. function normalizeAsyncValidator(validator) {
  1195. if (validator.validate) {
  1196. return function (c) { return validator.validate(c); };
  1197. }
  1198. else {
  1199. return validator;
  1200. }
  1201. }
  1202. /**
  1203. * @license
  1204. * Copyright Google Inc. All Rights Reserved.
  1205. *
  1206. * Use of this source code is governed by an MIT-style license that can be
  1207. * found in the LICENSE file at https://angular.io/license
  1208. */
  1209. var NUMBER_VALUE_ACCESSOR = {
  1210. provide: NG_VALUE_ACCESSOR,
  1211. useExisting: core.forwardRef(function () { return NumberValueAccessor; }),
  1212. multi: true
  1213. };
  1214. /**
  1215. * @description
  1216. * The `ControlValueAccessor` for writing a number value and listening to number input changes.
  1217. * The value accessor is used by the `FormControlDirective`, `FormControlName`, and `NgModel`
  1218. * directives.
  1219. *
  1220. * @usageNotes
  1221. *
  1222. * ### Using a number input with a reactive form.
  1223. *
  1224. * The following example shows how to use a number input with a reactive form.
  1225. *
  1226. * ```ts
  1227. * const totalCountControl = new FormControl();
  1228. * ```
  1229. *
  1230. * ```
  1231. * <input type="number" [formControl]="totalCountControl">
  1232. * ```
  1233. *
  1234. * @ngModule ReactiveFormsModule
  1235. * @ngModule FormsModule
  1236. * @publicApi
  1237. */
  1238. var NumberValueAccessor = /** @class */ (function () {
  1239. function NumberValueAccessor(_renderer, _elementRef) {
  1240. this._renderer = _renderer;
  1241. this._elementRef = _elementRef;
  1242. /**
  1243. * @description
  1244. * The registered callback function called when a change or input event occurs on the input
  1245. * element.
  1246. */
  1247. this.onChange = function (_) { };
  1248. /**
  1249. * @description
  1250. * The registered callback function called when a blur event occurs on the input element.
  1251. */
  1252. this.onTouched = function () { };
  1253. }
  1254. /**
  1255. * Sets the "value" property on the input element.
  1256. *
  1257. * @param value The checked value
  1258. */
  1259. NumberValueAccessor.prototype.writeValue = function (value) {
  1260. // The value needs to be normalized for IE9, otherwise it is set to 'null' when null
  1261. var normalizedValue = value == null ? '' : value;
  1262. this._renderer.setProperty(this._elementRef.nativeElement, 'value', normalizedValue);
  1263. };
  1264. /**
  1265. * @description
  1266. * Registers a function called when the control value changes.
  1267. *
  1268. * @param fn The callback function
  1269. */
  1270. NumberValueAccessor.prototype.registerOnChange = function (fn) {
  1271. this.onChange = function (value) { fn(value == '' ? null : parseFloat(value)); };
  1272. };
  1273. /**
  1274. * @description
  1275. * Registers a function called when the control is touched.
  1276. *
  1277. * @param fn The callback function
  1278. */
  1279. NumberValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  1280. /**
  1281. * Sets the "disabled" property on the input element.
  1282. *
  1283. * @param isDisabled The disabled value
  1284. */
  1285. NumberValueAccessor.prototype.setDisabledState = function (isDisabled) {
  1286. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  1287. };
  1288. NumberValueAccessor = __decorate([
  1289. core.Directive({
  1290. selector: 'input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]',
  1291. host: {
  1292. '(change)': 'onChange($event.target.value)',
  1293. '(input)': 'onChange($event.target.value)',
  1294. '(blur)': 'onTouched()'
  1295. },
  1296. providers: [NUMBER_VALUE_ACCESSOR]
  1297. }),
  1298. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef])
  1299. ], NumberValueAccessor);
  1300. return NumberValueAccessor;
  1301. }());
  1302. /**
  1303. * @license
  1304. * Copyright Google Inc. All Rights Reserved.
  1305. *
  1306. * Use of this source code is governed by an MIT-style license that can be
  1307. * found in the LICENSE file at https://angular.io/license
  1308. */
  1309. var RADIO_VALUE_ACCESSOR = {
  1310. provide: NG_VALUE_ACCESSOR,
  1311. useExisting: core.forwardRef(function () { return RadioControlValueAccessor; }),
  1312. multi: true
  1313. };
  1314. /**
  1315. * @description
  1316. * Class used by Angular to track radio buttons. For internal use only.
  1317. */
  1318. var RadioControlRegistry = /** @class */ (function () {
  1319. function RadioControlRegistry() {
  1320. this._accessors = [];
  1321. }
  1322. /**
  1323. * @description
  1324. * Adds a control to the internal registry. For internal use only.
  1325. */
  1326. RadioControlRegistry.prototype.add = function (control, accessor) {
  1327. this._accessors.push([control, accessor]);
  1328. };
  1329. /**
  1330. * @description
  1331. * Removes a control from the internal registry. For internal use only.
  1332. */
  1333. RadioControlRegistry.prototype.remove = function (accessor) {
  1334. for (var i = this._accessors.length - 1; i >= 0; --i) {
  1335. if (this._accessors[i][1] === accessor) {
  1336. this._accessors.splice(i, 1);
  1337. return;
  1338. }
  1339. }
  1340. };
  1341. /**
  1342. * @description
  1343. * Selects a radio button. For internal use only.
  1344. */
  1345. RadioControlRegistry.prototype.select = function (accessor) {
  1346. var _this = this;
  1347. this._accessors.forEach(function (c) {
  1348. if (_this._isSameGroup(c, accessor) && c[1] !== accessor) {
  1349. c[1].fireUncheck(accessor.value);
  1350. }
  1351. });
  1352. };
  1353. RadioControlRegistry.prototype._isSameGroup = function (controlPair, accessor) {
  1354. if (!controlPair[0].control)
  1355. return false;
  1356. return controlPair[0]._parent === accessor._control._parent &&
  1357. controlPair[1].name === accessor.name;
  1358. };
  1359. RadioControlRegistry = __decorate([
  1360. core.Injectable()
  1361. ], RadioControlRegistry);
  1362. return RadioControlRegistry;
  1363. }());
  1364. /**
  1365. * @description
  1366. * The `ControlValueAccessor` for writing radio control values and listening to radio control
  1367. * changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and
  1368. * `NgModel` directives.
  1369. *
  1370. * @usageNotes
  1371. *
  1372. * ### Using radio buttons with reactive form directives
  1373. *
  1374. * The follow example shows how to use radio buttons in a reactive form. When using radio buttons in
  1375. * a reactive form, radio buttons in the same group should have the same `formControlName`.
  1376. * Providing a `name` attribute is optional.
  1377. *
  1378. * {@example forms/ts/reactiveRadioButtons/reactive_radio_button_example.ts region='Reactive'}
  1379. *
  1380. * @ngModule ReactiveFormsModule
  1381. * @ngModule FormsModule
  1382. * @publicApi
  1383. */
  1384. var RadioControlValueAccessor = /** @class */ (function () {
  1385. function RadioControlValueAccessor(_renderer, _elementRef, _registry, _injector) {
  1386. this._renderer = _renderer;
  1387. this._elementRef = _elementRef;
  1388. this._registry = _registry;
  1389. this._injector = _injector;
  1390. /**
  1391. * @description
  1392. * The registered callback function called when a change event occurs on the input element.
  1393. */
  1394. this.onChange = function () { };
  1395. /**
  1396. * @description
  1397. * The registered callback function called when a blur event occurs on the input element.
  1398. */
  1399. this.onTouched = function () { };
  1400. }
  1401. /**
  1402. * @description
  1403. * A lifecycle method called when the directive is initialized. For internal use only.
  1404. *
  1405. * @param changes A object of key/value pairs for the set of changed inputs.
  1406. */
  1407. RadioControlValueAccessor.prototype.ngOnInit = function () {
  1408. this._control = this._injector.get(NgControl);
  1409. this._checkName();
  1410. this._registry.add(this._control, this);
  1411. };
  1412. /**
  1413. * @description
  1414. * Lifecycle method called before the directive's instance is destroyed. For internal use only.
  1415. *
  1416. * @param changes A object of key/value pairs for the set of changed inputs.
  1417. */
  1418. RadioControlValueAccessor.prototype.ngOnDestroy = function () { this._registry.remove(this); };
  1419. /**
  1420. * @description
  1421. * Sets the "checked" property value on the radio input element.
  1422. *
  1423. * @param value The checked value
  1424. */
  1425. RadioControlValueAccessor.prototype.writeValue = function (value) {
  1426. this._state = value === this.value;
  1427. this._renderer.setProperty(this._elementRef.nativeElement, 'checked', this._state);
  1428. };
  1429. /**
  1430. * @description
  1431. * Registers a function called when the control value changes.
  1432. *
  1433. * @param fn The callback function
  1434. */
  1435. RadioControlValueAccessor.prototype.registerOnChange = function (fn) {
  1436. var _this = this;
  1437. this._fn = fn;
  1438. this.onChange = function () {
  1439. fn(_this.value);
  1440. _this._registry.select(_this);
  1441. };
  1442. };
  1443. /**
  1444. * Sets the "value" on the radio input element and unchecks it.
  1445. *
  1446. * @param value
  1447. */
  1448. RadioControlValueAccessor.prototype.fireUncheck = function (value) { this.writeValue(value); };
  1449. /**
  1450. * @description
  1451. * Registers a function called when the control is touched.
  1452. *
  1453. * @param fn The callback function
  1454. */
  1455. RadioControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  1456. /**
  1457. * Sets the "disabled" property on the input element.
  1458. *
  1459. * @param isDisabled The disabled value
  1460. */
  1461. RadioControlValueAccessor.prototype.setDisabledState = function (isDisabled) {
  1462. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  1463. };
  1464. RadioControlValueAccessor.prototype._checkName = function () {
  1465. if (this.name && this.formControlName && this.name !== this.formControlName) {
  1466. this._throwNameError();
  1467. }
  1468. if (!this.name && this.formControlName)
  1469. this.name = this.formControlName;
  1470. };
  1471. RadioControlValueAccessor.prototype._throwNameError = function () {
  1472. throw new Error("\n If you define both a name and a formControlName attribute on your radio button, their values\n must match. Ex: <input type=\"radio\" formControlName=\"food\" name=\"food\">\n ");
  1473. };
  1474. __decorate([
  1475. core.Input(),
  1476. __metadata("design:type", String)
  1477. ], RadioControlValueAccessor.prototype, "name", void 0);
  1478. __decorate([
  1479. core.Input(),
  1480. __metadata("design:type", String)
  1481. ], RadioControlValueAccessor.prototype, "formControlName", void 0);
  1482. __decorate([
  1483. core.Input(),
  1484. __metadata("design:type", Object)
  1485. ], RadioControlValueAccessor.prototype, "value", void 0);
  1486. RadioControlValueAccessor = __decorate([
  1487. core.Directive({
  1488. selector: 'input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]',
  1489. host: { '(change)': 'onChange()', '(blur)': 'onTouched()' },
  1490. providers: [RADIO_VALUE_ACCESSOR]
  1491. }),
  1492. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef,
  1493. RadioControlRegistry, core.Injector])
  1494. ], RadioControlValueAccessor);
  1495. return RadioControlValueAccessor;
  1496. }());
  1497. /**
  1498. * @license
  1499. * Copyright Google Inc. All Rights Reserved.
  1500. *
  1501. * Use of this source code is governed by an MIT-style license that can be
  1502. * found in the LICENSE file at https://angular.io/license
  1503. */
  1504. var RANGE_VALUE_ACCESSOR = {
  1505. provide: NG_VALUE_ACCESSOR,
  1506. useExisting: core.forwardRef(function () { return RangeValueAccessor; }),
  1507. multi: true
  1508. };
  1509. /**
  1510. * @description
  1511. * The `ControlValueAccessor` for writing a range value and listening to range input changes.
  1512. * The value accessor is used by the `FormControlDirective`, `FormControlName`, and `NgModel`
  1513. * directives.
  1514. *
  1515. * @usageNotes
  1516. *
  1517. * ### Using a range input with a reactive form
  1518. *
  1519. * The following example shows how to use a range input with a reactive form.
  1520. *
  1521. * ```ts
  1522. * const ageControl = new FormControl();
  1523. * ```
  1524. *
  1525. * ```
  1526. * <input type="range" [formControl]="ageControl">
  1527. * ```
  1528. *
  1529. * @ngModule ReactiveFormsModule
  1530. * @ngModule FormsModule
  1531. * @publicApi
  1532. */
  1533. var RangeValueAccessor = /** @class */ (function () {
  1534. function RangeValueAccessor(_renderer, _elementRef) {
  1535. this._renderer = _renderer;
  1536. this._elementRef = _elementRef;
  1537. /**
  1538. * @description
  1539. * The registered callback function called when a change or input event occurs on the input
  1540. * element.
  1541. */
  1542. this.onChange = function (_) { };
  1543. /**
  1544. * @description
  1545. * The registered callback function called when a blur event occurs on the input element.
  1546. */
  1547. this.onTouched = function () { };
  1548. }
  1549. /**
  1550. * Sets the "value" property on the input element.
  1551. *
  1552. * @param value The checked value
  1553. */
  1554. RangeValueAccessor.prototype.writeValue = function (value) {
  1555. this._renderer.setProperty(this._elementRef.nativeElement, 'value', parseFloat(value));
  1556. };
  1557. /**
  1558. * @description
  1559. * Registers a function called when the control value changes.
  1560. *
  1561. * @param fn The callback function
  1562. */
  1563. RangeValueAccessor.prototype.registerOnChange = function (fn) {
  1564. this.onChange = function (value) { fn(value == '' ? null : parseFloat(value)); };
  1565. };
  1566. /**
  1567. * @description
  1568. * Registers a function called when the control is touched.
  1569. *
  1570. * @param fn The callback function
  1571. */
  1572. RangeValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  1573. /**
  1574. * Sets the "disabled" property on the range input element.
  1575. *
  1576. * @param isDisabled The disabled value
  1577. */
  1578. RangeValueAccessor.prototype.setDisabledState = function (isDisabled) {
  1579. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  1580. };
  1581. RangeValueAccessor = __decorate([
  1582. core.Directive({
  1583. selector: 'input[type=range][formControlName],input[type=range][formControl],input[type=range][ngModel]',
  1584. host: {
  1585. '(change)': 'onChange($event.target.value)',
  1586. '(input)': 'onChange($event.target.value)',
  1587. '(blur)': 'onTouched()'
  1588. },
  1589. providers: [RANGE_VALUE_ACCESSOR]
  1590. }),
  1591. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef])
  1592. ], RangeValueAccessor);
  1593. return RangeValueAccessor;
  1594. }());
  1595. /**
  1596. * @license
  1597. * Copyright Google Inc. All Rights Reserved.
  1598. *
  1599. * Use of this source code is governed by an MIT-style license that can be
  1600. * found in the LICENSE file at https://angular.io/license
  1601. */
  1602. var FormErrorExamples = {
  1603. formControlName: "\n <div [formGroup]=\"myGroup\">\n <input formControlName=\"firstName\">\n </div>\n\n In your class:\n\n this.myGroup = new FormGroup({\n firstName: new FormControl()\n });",
  1604. formGroupName: "\n <div [formGroup]=\"myGroup\">\n <div formGroupName=\"person\">\n <input formControlName=\"firstName\">\n </div>\n </div>\n\n In your class:\n\n this.myGroup = new FormGroup({\n person: new FormGroup({ firstName: new FormControl() })\n });",
  1605. formArrayName: "\n <div [formGroup]=\"myGroup\">\n <div formArrayName=\"cities\">\n <div *ngFor=\"let city of cityArray.controls; index as i\">\n <input [formControlName]=\"i\">\n </div>\n </div>\n </div>\n\n In your class:\n\n this.cityArray = new FormArray([new FormControl('SF')]);\n this.myGroup = new FormGroup({\n cities: this.cityArray\n });",
  1606. ngModelGroup: "\n <form>\n <div ngModelGroup=\"person\">\n <input [(ngModel)]=\"person.name\" name=\"firstName\">\n </div>\n </form>",
  1607. ngModelWithFormGroup: "\n <div [formGroup]=\"myGroup\">\n <input formControlName=\"firstName\">\n <input [(ngModel)]=\"showMoreControls\" [ngModelOptions]=\"{standalone: true}\">\n </div>\n "
  1608. };
  1609. /**
  1610. * @license
  1611. * Copyright Google Inc. All Rights Reserved.
  1612. *
  1613. * Use of this source code is governed by an MIT-style license that can be
  1614. * found in the LICENSE file at https://angular.io/license
  1615. */
  1616. var ReactiveErrors = /** @class */ (function () {
  1617. function ReactiveErrors() {
  1618. }
  1619. ReactiveErrors.controlParentException = function () {
  1620. throw new Error("formControlName must be used with a parent formGroup directive. You'll want to add a formGroup\n directive and pass it an existing FormGroup instance (you can create one in your class).\n\n Example:\n\n " + FormErrorExamples.formControlName);
  1621. };
  1622. ReactiveErrors.ngModelGroupException = function () {
  1623. throw new Error("formControlName cannot be used with an ngModelGroup parent. It is only compatible with parents\n that also have a \"form\" prefix: formGroupName, formArrayName, or formGroup.\n\n Option 1: Update the parent to be formGroupName (reactive form strategy)\n\n " + FormErrorExamples.formGroupName + "\n\n Option 2: Use ngModel instead of formControlName (template-driven strategy)\n\n " + FormErrorExamples.ngModelGroup);
  1624. };
  1625. ReactiveErrors.missingFormException = function () {
  1626. throw new Error("formGroup expects a FormGroup instance. Please pass one in.\n\n Example:\n\n " + FormErrorExamples.formControlName);
  1627. };
  1628. ReactiveErrors.groupParentException = function () {
  1629. throw new Error("formGroupName must be used with a parent formGroup directive. You'll want to add a formGroup\n directive and pass it an existing FormGroup instance (you can create one in your class).\n\n Example:\n\n " + FormErrorExamples.formGroupName);
  1630. };
  1631. ReactiveErrors.arrayParentException = function () {
  1632. throw new Error("formArrayName must be used with a parent formGroup directive. You'll want to add a formGroup\n directive and pass it an existing FormGroup instance (you can create one in your class).\n\n Example:\n\n " + FormErrorExamples.formArrayName);
  1633. };
  1634. ReactiveErrors.disabledAttrWarning = function () {
  1635. console.warn("\n It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true\n when you set up this control in your component class, the disabled attribute will actually be set in the DOM for\n you. We recommend using this approach to avoid 'changed after checked' errors.\n \n Example: \n form = new FormGroup({\n first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),\n last: new FormControl('Drew', Validators.required)\n });\n ");
  1636. };
  1637. ReactiveErrors.ngModelWarning = function (directiveName) {
  1638. console.warn("\n It looks like you're using ngModel on the same form field as " + directiveName + ". \n Support for using the ngModel input property and ngModelChange event with \n reactive form directives has been deprecated in Angular v6 and will be removed \n in Angular v7.\n \n For more information on this, see our API docs here:\n https://angular.io/api/forms/" + (directiveName === 'formControl' ? 'FormControlDirective'
  1639. : 'FormControlName') + "#use-with-ngmodel\n ");
  1640. };
  1641. return ReactiveErrors;
  1642. }());
  1643. /**
  1644. * @license
  1645. * Copyright Google Inc. All Rights Reserved.
  1646. *
  1647. * Use of this source code is governed by an MIT-style license that can be
  1648. * found in the LICENSE file at https://angular.io/license
  1649. */
  1650. var SELECT_VALUE_ACCESSOR = {
  1651. provide: NG_VALUE_ACCESSOR,
  1652. useExisting: core.forwardRef(function () { return SelectControlValueAccessor; }),
  1653. multi: true
  1654. };
  1655. function _buildValueString(id, value) {
  1656. if (id == null)
  1657. return "" + value;
  1658. if (value && typeof value === 'object')
  1659. value = 'Object';
  1660. return (id + ": " + value).slice(0, 50);
  1661. }
  1662. function _extractId(valueString) {
  1663. return valueString.split(':')[0];
  1664. }
  1665. /**
  1666. * @description
  1667. * The `ControlValueAccessor` for writing select control values and listening to select control
  1668. * changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and
  1669. * `NgModel` directives.
  1670. *
  1671. * @usageNotes
  1672. *
  1673. * ### Using select controls in a reactive form
  1674. *
  1675. * The following examples show how to use a select control in a reactive form.
  1676. *
  1677. * {@example forms/ts/reactiveSelectControl/reactive_select_control_example.ts region='Component'}
  1678. *
  1679. * ### Using select controls in a template-driven form
  1680. *
  1681. * To use a select in a template-driven form, simply add an `ngModel` and a `name`
  1682. * attribute to the main `<select>` tag.
  1683. *
  1684. * {@example forms/ts/selectControl/select_control_example.ts region='Component'}
  1685. *
  1686. * ### Customizing option selection
  1687. *
  1688. * Angular uses object identity to select option. It's possible for the identities of items
  1689. * to change while the data does not. This can happen, for example, if the items are produced
  1690. * from an RPC to the server, and that RPC is re-run. Even if the data hasn't changed, the
  1691. * second response will produce objects with different identities.
  1692. *
  1693. * To customize the default option comparison algorithm, `<select>` supports `compareWith` input.
  1694. * `compareWith` takes a **function** which has two arguments: `option1` and `option2`.
  1695. * If `compareWith` is given, Angular selects option by the return value of the function.
  1696. *
  1697. * ```ts
  1698. * const selectedCountriesControl = new FormControl();
  1699. * ```
  1700. *
  1701. * ```
  1702. * <select [compareWith]="compareFn" [formControl]="selectedCountriesControl">
  1703. * <option *ngFor="let country of countries" [ngValue]="country">
  1704. * {{country.name}}
  1705. * </option>
  1706. * </select>
  1707. *
  1708. * compareFn(c1: Country, c2: Country): boolean {
  1709. * return c1 && c2 ? c1.id === c2.id : c1 === c2;
  1710. * }
  1711. * ```
  1712. *
  1713. * **Note:** We listen to the 'change' event because 'input' events aren't fired
  1714. * for selects in Firefox and IE:
  1715. * https://bugzilla.mozilla.org/show_bug.cgi?id=1024350
  1716. * https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4660045/
  1717. *
  1718. * @ngModule ReactiveFormsModule
  1719. * @ngModule FormsModule
  1720. * @publicApi
  1721. */
  1722. var SelectControlValueAccessor = /** @class */ (function () {
  1723. function SelectControlValueAccessor(_renderer, _elementRef) {
  1724. this._renderer = _renderer;
  1725. this._elementRef = _elementRef;
  1726. /** @internal */
  1727. this._optionMap = new Map();
  1728. /** @internal */
  1729. this._idCounter = 0;
  1730. /**
  1731. * @description
  1732. * The registered callback function called when a change event occurs on the input element.
  1733. */
  1734. this.onChange = function (_) { };
  1735. /**
  1736. * @description
  1737. * The registered callback function called when a blur event occurs on the input element.
  1738. */
  1739. this.onTouched = function () { };
  1740. this._compareWith = core.ɵlooseIdentical;
  1741. }
  1742. Object.defineProperty(SelectControlValueAccessor.prototype, "compareWith", {
  1743. /**
  1744. * @description
  1745. * Tracks the option comparison algorithm for tracking identities when
  1746. * checking for changes.
  1747. */
  1748. set: function (fn) {
  1749. if (typeof fn !== 'function') {
  1750. throw new Error("compareWith must be a function, but received " + JSON.stringify(fn));
  1751. }
  1752. this._compareWith = fn;
  1753. },
  1754. enumerable: true,
  1755. configurable: true
  1756. });
  1757. /**
  1758. * Sets the "value" property on the input element. The "selectedIndex"
  1759. * property is also set if an ID is provided on the option element.
  1760. *
  1761. * @param value The checked value
  1762. */
  1763. SelectControlValueAccessor.prototype.writeValue = function (value) {
  1764. this.value = value;
  1765. var id = this._getOptionId(value);
  1766. if (id == null) {
  1767. this._renderer.setProperty(this._elementRef.nativeElement, 'selectedIndex', -1);
  1768. }
  1769. var valueString = _buildValueString(id, value);
  1770. this._renderer.setProperty(this._elementRef.nativeElement, 'value', valueString);
  1771. };
  1772. /**
  1773. * @description
  1774. * Registers a function called when the control value changes.
  1775. *
  1776. * @param fn The callback function
  1777. */
  1778. SelectControlValueAccessor.prototype.registerOnChange = function (fn) {
  1779. var _this = this;
  1780. this.onChange = function (valueString) {
  1781. _this.value = _this._getOptionValue(valueString);
  1782. fn(_this.value);
  1783. };
  1784. };
  1785. /**
  1786. * @description
  1787. * Registers a function called when the control is touched.
  1788. *
  1789. * @param fn The callback function
  1790. */
  1791. SelectControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  1792. /**
  1793. * Sets the "disabled" property on the select input element.
  1794. *
  1795. * @param isDisabled The disabled value
  1796. */
  1797. SelectControlValueAccessor.prototype.setDisabledState = function (isDisabled) {
  1798. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  1799. };
  1800. /** @internal */
  1801. SelectControlValueAccessor.prototype._registerOption = function () { return (this._idCounter++).toString(); };
  1802. /** @internal */
  1803. SelectControlValueAccessor.prototype._getOptionId = function (value) {
  1804. var e_1, _a;
  1805. try {
  1806. for (var _b = __values(Array.from(this._optionMap.keys())), _c = _b.next(); !_c.done; _c = _b.next()) {
  1807. var id = _c.value;
  1808. if (this._compareWith(this._optionMap.get(id), value))
  1809. return id;
  1810. }
  1811. }
  1812. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1813. finally {
  1814. try {
  1815. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1816. }
  1817. finally { if (e_1) throw e_1.error; }
  1818. }
  1819. return null;
  1820. };
  1821. /** @internal */
  1822. SelectControlValueAccessor.prototype._getOptionValue = function (valueString) {
  1823. var id = _extractId(valueString);
  1824. return this._optionMap.has(id) ? this._optionMap.get(id) : valueString;
  1825. };
  1826. __decorate([
  1827. core.Input(),
  1828. __metadata("design:type", Function),
  1829. __metadata("design:paramtypes", [Function])
  1830. ], SelectControlValueAccessor.prototype, "compareWith", null);
  1831. SelectControlValueAccessor = __decorate([
  1832. core.Directive({
  1833. selector: 'select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]',
  1834. host: { '(change)': 'onChange($event.target.value)', '(blur)': 'onTouched()' },
  1835. providers: [SELECT_VALUE_ACCESSOR]
  1836. }),
  1837. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef])
  1838. ], SelectControlValueAccessor);
  1839. return SelectControlValueAccessor;
  1840. }());
  1841. /**
  1842. * @description
  1843. * Marks `<option>` as dynamic, so Angular can be notified when options change.
  1844. *
  1845. * @see `SelectControlValueAccessor`
  1846. *
  1847. * @ngModule ReactiveFormsModule
  1848. * @ngModule FormsModule
  1849. * @publicApi
  1850. */
  1851. var NgSelectOption = /** @class */ (function () {
  1852. function NgSelectOption(_element, _renderer, _select) {
  1853. this._element = _element;
  1854. this._renderer = _renderer;
  1855. this._select = _select;
  1856. if (this._select)
  1857. this.id = this._select._registerOption();
  1858. }
  1859. Object.defineProperty(NgSelectOption.prototype, "ngValue", {
  1860. /**
  1861. * @description
  1862. * Tracks the value bound to the option element. Unlike the value binding,
  1863. * ngValue supports binding to objects.
  1864. */
  1865. set: function (value) {
  1866. if (this._select == null)
  1867. return;
  1868. this._select._optionMap.set(this.id, value);
  1869. this._setElementValue(_buildValueString(this.id, value));
  1870. this._select.writeValue(this._select.value);
  1871. },
  1872. enumerable: true,
  1873. configurable: true
  1874. });
  1875. Object.defineProperty(NgSelectOption.prototype, "value", {
  1876. /**
  1877. * @description
  1878. * Tracks simple string values bound to the option element.
  1879. * For objects, use the `ngValue` input binding.
  1880. */
  1881. set: function (value) {
  1882. this._setElementValue(value);
  1883. if (this._select)
  1884. this._select.writeValue(this._select.value);
  1885. },
  1886. enumerable: true,
  1887. configurable: true
  1888. });
  1889. /** @internal */
  1890. NgSelectOption.prototype._setElementValue = function (value) {
  1891. this._renderer.setProperty(this._element.nativeElement, 'value', value);
  1892. };
  1893. /**
  1894. * @description
  1895. * Lifecycle method called before the directive's instance is destroyed. For internal use only.
  1896. */
  1897. NgSelectOption.prototype.ngOnDestroy = function () {
  1898. if (this._select) {
  1899. this._select._optionMap.delete(this.id);
  1900. this._select.writeValue(this._select.value);
  1901. }
  1902. };
  1903. __decorate([
  1904. core.Input('ngValue'),
  1905. __metadata("design:type", Object),
  1906. __metadata("design:paramtypes", [Object])
  1907. ], NgSelectOption.prototype, "ngValue", null);
  1908. __decorate([
  1909. core.Input('value'),
  1910. __metadata("design:type", Object),
  1911. __metadata("design:paramtypes", [Object])
  1912. ], NgSelectOption.prototype, "value", null);
  1913. NgSelectOption = __decorate([
  1914. core.Directive({ selector: 'option' }),
  1915. __param(2, core.Optional()), __param(2, core.Host()),
  1916. __metadata("design:paramtypes", [core.ElementRef, core.Renderer2,
  1917. SelectControlValueAccessor])
  1918. ], NgSelectOption);
  1919. return NgSelectOption;
  1920. }());
  1921. /**
  1922. * @license
  1923. * Copyright Google Inc. All Rights Reserved.
  1924. *
  1925. * Use of this source code is governed by an MIT-style license that can be
  1926. * found in the LICENSE file at https://angular.io/license
  1927. */
  1928. var SELECT_MULTIPLE_VALUE_ACCESSOR = {
  1929. provide: NG_VALUE_ACCESSOR,
  1930. useExisting: core.forwardRef(function () { return SelectMultipleControlValueAccessor; }),
  1931. multi: true
  1932. };
  1933. function _buildValueString$1(id, value) {
  1934. if (id == null)
  1935. return "" + value;
  1936. if (typeof value === 'string')
  1937. value = "'" + value + "'";
  1938. if (value && typeof value === 'object')
  1939. value = 'Object';
  1940. return (id + ": " + value).slice(0, 50);
  1941. }
  1942. function _extractId$1(valueString) {
  1943. return valueString.split(':')[0];
  1944. }
  1945. /**
  1946. * @description
  1947. * The `ControlValueAccessor` for writing multi-select control values and listening to multi-select control
  1948. * changes. The value accessor is used by the `FormControlDirective`, `FormControlName`, and `NgModel`
  1949. * directives.
  1950. *
  1951. * @see `SelectControlValueAccessor`
  1952. *
  1953. * @usageNotes
  1954. *
  1955. * ### Using a multi-select control
  1956. *
  1957. * The follow example shows you how to use a multi-select control with a reactive form.
  1958. *
  1959. * ```ts
  1960. * const countryControl = new FormControl();
  1961. * ```
  1962. *
  1963. * ```
  1964. * <select multiple name="countries" [formControl]="countryControl">
  1965. * <option *ngFor="let country of countries" [ngValue]="country">
  1966. * {{ country.name }}
  1967. * </option>
  1968. * </select>
  1969. * ```
  1970. *
  1971. * ### Customizing option selection
  1972. *
  1973. * To customize the default option comparison algorithm, `<select>` supports `compareWith` input.
  1974. * See the `SelectControlValueAccessor` for usage.
  1975. *
  1976. * @ngModule ReactiveFormsModule
  1977. * @ngModule FormsModule
  1978. * @publicApi
  1979. */
  1980. var SelectMultipleControlValueAccessor = /** @class */ (function () {
  1981. function SelectMultipleControlValueAccessor(_renderer, _elementRef) {
  1982. this._renderer = _renderer;
  1983. this._elementRef = _elementRef;
  1984. /** @internal */
  1985. this._optionMap = new Map();
  1986. /** @internal */
  1987. this._idCounter = 0;
  1988. /**
  1989. * @description
  1990. * The registered callback function called when a change event occurs on the input element.
  1991. */
  1992. this.onChange = function (_) { };
  1993. /**
  1994. * @description
  1995. * The registered callback function called when a blur event occurs on the input element.
  1996. */
  1997. this.onTouched = function () { };
  1998. this._compareWith = core.ɵlooseIdentical;
  1999. }
  2000. Object.defineProperty(SelectMultipleControlValueAccessor.prototype, "compareWith", {
  2001. /**
  2002. * @description
  2003. * Tracks the option comparison algorithm for tracking identities when
  2004. * checking for changes.
  2005. */
  2006. set: function (fn) {
  2007. if (typeof fn !== 'function') {
  2008. throw new Error("compareWith must be a function, but received " + JSON.stringify(fn));
  2009. }
  2010. this._compareWith = fn;
  2011. },
  2012. enumerable: true,
  2013. configurable: true
  2014. });
  2015. /**
  2016. * @description
  2017. * Sets the "value" property on one or of more
  2018. * of the select's options.
  2019. *
  2020. * @param value The value
  2021. */
  2022. SelectMultipleControlValueAccessor.prototype.writeValue = function (value) {
  2023. var _this = this;
  2024. this.value = value;
  2025. var optionSelectedStateSetter;
  2026. if (Array.isArray(value)) {
  2027. // convert values to ids
  2028. var ids_1 = value.map(function (v) { return _this._getOptionId(v); });
  2029. optionSelectedStateSetter = function (opt, o) { opt._setSelected(ids_1.indexOf(o.toString()) > -1); };
  2030. }
  2031. else {
  2032. optionSelectedStateSetter = function (opt, o) { opt._setSelected(false); };
  2033. }
  2034. this._optionMap.forEach(optionSelectedStateSetter);
  2035. };
  2036. /**
  2037. * @description
  2038. * Registers a function called when the control value changes
  2039. * and writes an array of the selected options.
  2040. *
  2041. * @param fn The callback function
  2042. */
  2043. SelectMultipleControlValueAccessor.prototype.registerOnChange = function (fn) {
  2044. var _this = this;
  2045. this.onChange = function (_) {
  2046. var selected = [];
  2047. if (_.hasOwnProperty('selectedOptions')) {
  2048. var options = _.selectedOptions;
  2049. for (var i = 0; i < options.length; i++) {
  2050. var opt = options.item(i);
  2051. var val = _this._getOptionValue(opt.value);
  2052. selected.push(val);
  2053. }
  2054. }
  2055. // Degrade on IE
  2056. else {
  2057. var options = _.options;
  2058. for (var i = 0; i < options.length; i++) {
  2059. var opt = options.item(i);
  2060. if (opt.selected) {
  2061. var val = _this._getOptionValue(opt.value);
  2062. selected.push(val);
  2063. }
  2064. }
  2065. }
  2066. _this.value = selected;
  2067. fn(selected);
  2068. };
  2069. };
  2070. /**
  2071. * @description
  2072. * Registers a function called when the control is touched.
  2073. *
  2074. * @param fn The callback function
  2075. */
  2076. SelectMultipleControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
  2077. /**
  2078. * Sets the "disabled" property on the select input element.
  2079. *
  2080. * @param isDisabled The disabled value
  2081. */
  2082. SelectMultipleControlValueAccessor.prototype.setDisabledState = function (isDisabled) {
  2083. this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
  2084. };
  2085. /** @internal */
  2086. SelectMultipleControlValueAccessor.prototype._registerOption = function (value) {
  2087. var id = (this._idCounter++).toString();
  2088. this._optionMap.set(id, value);
  2089. return id;
  2090. };
  2091. /** @internal */
  2092. SelectMultipleControlValueAccessor.prototype._getOptionId = function (value) {
  2093. var e_1, _a;
  2094. try {
  2095. for (var _b = __values(Array.from(this._optionMap.keys())), _c = _b.next(); !_c.done; _c = _b.next()) {
  2096. var id = _c.value;
  2097. if (this._compareWith(this._optionMap.get(id)._value, value))
  2098. return id;
  2099. }
  2100. }
  2101. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2102. finally {
  2103. try {
  2104. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  2105. }
  2106. finally { if (e_1) throw e_1.error; }
  2107. }
  2108. return null;
  2109. };
  2110. /** @internal */
  2111. SelectMultipleControlValueAccessor.prototype._getOptionValue = function (valueString) {
  2112. var id = _extractId$1(valueString);
  2113. return this._optionMap.has(id) ? this._optionMap.get(id)._value : valueString;
  2114. };
  2115. __decorate([
  2116. core.Input(),
  2117. __metadata("design:type", Function),
  2118. __metadata("design:paramtypes", [Function])
  2119. ], SelectMultipleControlValueAccessor.prototype, "compareWith", null);
  2120. SelectMultipleControlValueAccessor = __decorate([
  2121. core.Directive({
  2122. selector: 'select[multiple][formControlName],select[multiple][formControl],select[multiple][ngModel]',
  2123. host: { '(change)': 'onChange($event.target)', '(blur)': 'onTouched()' },
  2124. providers: [SELECT_MULTIPLE_VALUE_ACCESSOR]
  2125. }),
  2126. __metadata("design:paramtypes", [core.Renderer2, core.ElementRef])
  2127. ], SelectMultipleControlValueAccessor);
  2128. return SelectMultipleControlValueAccessor;
  2129. }());
  2130. /**
  2131. * @description
  2132. * Marks `<option>` as dynamic, so Angular can be notified when options change.
  2133. *
  2134. * @see `SelectMultipleControlValueAccessor`
  2135. *
  2136. * @ngModule ReactiveFormsModule
  2137. * @ngModule FormsModule
  2138. * @publicApi
  2139. */
  2140. var ɵNgSelectMultipleOption = /** @class */ (function () {
  2141. function ɵNgSelectMultipleOption(_element, _renderer, _select) {
  2142. this._element = _element;
  2143. this._renderer = _renderer;
  2144. this._select = _select;
  2145. if (this._select) {
  2146. this.id = this._select._registerOption(this);
  2147. }
  2148. }
  2149. Object.defineProperty(ɵNgSelectMultipleOption.prototype, "ngValue", {
  2150. /**
  2151. * @description
  2152. * Tracks the value bound to the option element. Unlike the value binding,
  2153. * ngValue supports binding to objects.
  2154. */
  2155. set: function (value) {
  2156. if (this._select == null)
  2157. return;
  2158. this._value = value;
  2159. this._setElementValue(_buildValueString$1(this.id, value));
  2160. this._select.writeValue(this._select.value);
  2161. },
  2162. enumerable: true,
  2163. configurable: true
  2164. });
  2165. Object.defineProperty(ɵNgSelectMultipleOption.prototype, "value", {
  2166. /**
  2167. * @description
  2168. * Tracks simple string values bound to the option element.
  2169. * For objects, use the `ngValue` input binding.
  2170. */
  2171. set: function (value) {
  2172. if (this._select) {
  2173. this._value = value;
  2174. this._setElementValue(_buildValueString$1(this.id, value));
  2175. this._select.writeValue(this._select.value);
  2176. }
  2177. else {
  2178. this._setElementValue(value);
  2179. }
  2180. },
  2181. enumerable: true,
  2182. configurable: true
  2183. });
  2184. /** @internal */
  2185. ɵNgSelectMultipleOption.prototype._setElementValue = function (value) {
  2186. this._renderer.setProperty(this._element.nativeElement, 'value', value);
  2187. };
  2188. /** @internal */
  2189. ɵNgSelectMultipleOption.prototype._setSelected = function (selected) {
  2190. this._renderer.setProperty(this._element.nativeElement, 'selected', selected);
  2191. };
  2192. /**
  2193. * @description
  2194. * Lifecycle method called before the directive's instance is destroyed. For internal use only.
  2195. */
  2196. ɵNgSelectMultipleOption.prototype.ngOnDestroy = function () {
  2197. if (this._select) {
  2198. this._select._optionMap.delete(this.id);
  2199. this._select.writeValue(this._select.value);
  2200. }
  2201. };
  2202. __decorate([
  2203. core.Input('ngValue'),
  2204. __metadata("design:type", Object),
  2205. __metadata("design:paramtypes", [Object])
  2206. ], ɵNgSelectMultipleOption.prototype, "ngValue", null);
  2207. __decorate([
  2208. core.Input('value'),
  2209. __metadata("design:type", Object),
  2210. __metadata("design:paramtypes", [Object])
  2211. ], ɵNgSelectMultipleOption.prototype, "value", null);
  2212. ɵNgSelectMultipleOption = __decorate([
  2213. core.Directive({ selector: 'option' }),
  2214. __param(2, core.Optional()), __param(2, core.Host()),
  2215. __metadata("design:paramtypes", [core.ElementRef, core.Renderer2,
  2216. SelectMultipleControlValueAccessor])
  2217. ], ɵNgSelectMultipleOption);
  2218. return ɵNgSelectMultipleOption;
  2219. }());
  2220. /**
  2221. * @license
  2222. * Copyright Google Inc. All Rights Reserved.
  2223. *
  2224. * Use of this source code is governed by an MIT-style license that can be
  2225. * found in the LICENSE file at https://angular.io/license
  2226. */
  2227. function controlPath(name, parent) {
  2228. return __spread(parent.path, [name]);
  2229. }
  2230. function setUpControl(control, dir) {
  2231. if (!control)
  2232. _throwError(dir, 'Cannot find control with');
  2233. if (!dir.valueAccessor)
  2234. _throwError(dir, 'No value accessor for form control with');
  2235. control.validator = Validators.compose([control.validator, dir.validator]);
  2236. control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]);
  2237. dir.valueAccessor.writeValue(control.value);
  2238. setUpViewChangePipeline(control, dir);
  2239. setUpModelChangePipeline(control, dir);
  2240. setUpBlurPipeline(control, dir);
  2241. if (dir.valueAccessor.setDisabledState) {
  2242. control.registerOnDisabledChange(function (isDisabled) { dir.valueAccessor.setDisabledState(isDisabled); });
  2243. }
  2244. // re-run validation when validator binding changes, e.g. minlength=3 -> minlength=4
  2245. dir._rawValidators.forEach(function (validator) {
  2246. if (validator.registerOnValidatorChange)
  2247. validator.registerOnValidatorChange(function () { return control.updateValueAndValidity(); });
  2248. });
  2249. dir._rawAsyncValidators.forEach(function (validator) {
  2250. if (validator.registerOnValidatorChange)
  2251. validator.registerOnValidatorChange(function () { return control.updateValueAndValidity(); });
  2252. });
  2253. }
  2254. function cleanUpControl(control, dir) {
  2255. dir.valueAccessor.registerOnChange(function () { return _noControlError(dir); });
  2256. dir.valueAccessor.registerOnTouched(function () { return _noControlError(dir); });
  2257. dir._rawValidators.forEach(function (validator) {
  2258. if (validator.registerOnValidatorChange) {
  2259. validator.registerOnValidatorChange(null);
  2260. }
  2261. });
  2262. dir._rawAsyncValidators.forEach(function (validator) {
  2263. if (validator.registerOnValidatorChange) {
  2264. validator.registerOnValidatorChange(null);
  2265. }
  2266. });
  2267. if (control)
  2268. control._clearChangeFns();
  2269. }
  2270. function setUpViewChangePipeline(control, dir) {
  2271. dir.valueAccessor.registerOnChange(function (newValue) {
  2272. control._pendingValue = newValue;
  2273. control._pendingChange = true;
  2274. control._pendingDirty = true;
  2275. if (control.updateOn === 'change')
  2276. updateControl(control, dir);
  2277. });
  2278. }
  2279. function setUpBlurPipeline(control, dir) {
  2280. dir.valueAccessor.registerOnTouched(function () {
  2281. control._pendingTouched = true;
  2282. if (control.updateOn === 'blur' && control._pendingChange)
  2283. updateControl(control, dir);
  2284. if (control.updateOn !== 'submit')
  2285. control.markAsTouched();
  2286. });
  2287. }
  2288. function updateControl(control, dir) {
  2289. if (control._pendingDirty)
  2290. control.markAsDirty();
  2291. control.setValue(control._pendingValue, { emitModelToViewChange: false });
  2292. dir.viewToModelUpdate(control._pendingValue);
  2293. control._pendingChange = false;
  2294. }
  2295. function setUpModelChangePipeline(control, dir) {
  2296. control.registerOnChange(function (newValue, emitModelEvent) {
  2297. // control -> view
  2298. dir.valueAccessor.writeValue(newValue);
  2299. // control -> ngModel
  2300. if (emitModelEvent)
  2301. dir.viewToModelUpdate(newValue);
  2302. });
  2303. }
  2304. function setUpFormContainer(control, dir) {
  2305. if (control == null)
  2306. _throwError(dir, 'Cannot find control with');
  2307. control.validator = Validators.compose([control.validator, dir.validator]);
  2308. control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]);
  2309. }
  2310. function _noControlError(dir) {
  2311. return _throwError(dir, 'There is no FormControl instance attached to form control element with');
  2312. }
  2313. function _throwError(dir, message) {
  2314. var messageEnd;
  2315. if (dir.path.length > 1) {
  2316. messageEnd = "path: '" + dir.path.join(' -> ') + "'";
  2317. }
  2318. else if (dir.path[0]) {
  2319. messageEnd = "name: '" + dir.path + "'";
  2320. }
  2321. else {
  2322. messageEnd = 'unspecified name attribute';
  2323. }
  2324. throw new Error(message + " " + messageEnd);
  2325. }
  2326. function composeValidators(validators) {
  2327. return validators != null ? Validators.compose(validators.map(normalizeValidator)) : null;
  2328. }
  2329. function composeAsyncValidators(validators) {
  2330. return validators != null ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) :
  2331. null;
  2332. }
  2333. function isPropertyUpdated(changes, viewModel) {
  2334. if (!changes.hasOwnProperty('model'))
  2335. return false;
  2336. var change = changes['model'];
  2337. if (change.isFirstChange())
  2338. return true;
  2339. return !core.ɵlooseIdentical(viewModel, change.currentValue);
  2340. }
  2341. var BUILTIN_ACCESSORS = [
  2342. CheckboxControlValueAccessor,
  2343. RangeValueAccessor,
  2344. NumberValueAccessor,
  2345. SelectControlValueAccessor,
  2346. SelectMultipleControlValueAccessor,
  2347. RadioControlValueAccessor,
  2348. ];
  2349. function isBuiltInAccessor(valueAccessor) {
  2350. return BUILTIN_ACCESSORS.some(function (a) { return valueAccessor.constructor === a; });
  2351. }
  2352. function syncPendingControls(form, directives) {
  2353. form._syncPendingControls();
  2354. directives.forEach(function (dir) {
  2355. var control = dir.control;
  2356. if (control.updateOn === 'submit' && control._pendingChange) {
  2357. dir.viewToModelUpdate(control._pendingValue);
  2358. control._pendingChange = false;
  2359. }
  2360. });
  2361. }
  2362. // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented
  2363. function selectValueAccessor(dir, valueAccessors) {
  2364. if (!valueAccessors)
  2365. return null;
  2366. if (!Array.isArray(valueAccessors))
  2367. _throwError(dir, 'Value accessor was not provided as an array for form control with');
  2368. var defaultAccessor = undefined;
  2369. var builtinAccessor = undefined;
  2370. var customAccessor = undefined;
  2371. valueAccessors.forEach(function (v) {
  2372. if (v.constructor === DefaultValueAccessor) {
  2373. defaultAccessor = v;
  2374. }
  2375. else if (isBuiltInAccessor(v)) {
  2376. if (builtinAccessor)
  2377. _throwError(dir, 'More than one built-in value accessor matches form control with');
  2378. builtinAccessor = v;
  2379. }
  2380. else {
  2381. if (customAccessor)
  2382. _throwError(dir, 'More than one custom value accessor matches form control with');
  2383. customAccessor = v;
  2384. }
  2385. });
  2386. if (customAccessor)
  2387. return customAccessor;
  2388. if (builtinAccessor)
  2389. return builtinAccessor;
  2390. if (defaultAccessor)
  2391. return defaultAccessor;
  2392. _throwError(dir, 'No valid value accessor for form control with');
  2393. return null;
  2394. }
  2395. function removeDir(list, el) {
  2396. var index = list.indexOf(el);
  2397. if (index > -1)
  2398. list.splice(index, 1);
  2399. }
  2400. // TODO(kara): remove after deprecation period
  2401. function _ngModelWarning(name, type, instance, warningConfig) {
  2402. if (!core.isDevMode() || warningConfig === 'never')
  2403. return;
  2404. if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) ||
  2405. (warningConfig === 'always' && !instance._ngModelWarningSent)) {
  2406. ReactiveErrors.ngModelWarning(name);
  2407. type._ngModelWarningSentOnce = true;
  2408. instance._ngModelWarningSent = true;
  2409. }
  2410. }
  2411. /**
  2412. * @license
  2413. * Copyright Google Inc. All Rights Reserved.
  2414. *
  2415. * Use of this source code is governed by an MIT-style license that can be
  2416. * found in the LICENSE file at https://angular.io/license
  2417. */
  2418. /**
  2419. * Reports that a FormControl is valid, meaning that no errors exist in the input value.
  2420. *
  2421. * @see `status`
  2422. */
  2423. var VALID = 'VALID';
  2424. /**
  2425. * Reports that a FormControl is invalid, meaning that an error exists in the input value.
  2426. *
  2427. * @see `status`
  2428. */
  2429. var INVALID = 'INVALID';
  2430. /**
  2431. * Reports that a FormControl is pending, meaning that that async validation is occurring and
  2432. * errors are not yet available for the input value.
  2433. *
  2434. * @see `markAsPending`
  2435. * @see `status`
  2436. */
  2437. var PENDING = 'PENDING';
  2438. /**
  2439. * Reports that a FormControl is disabled, meaning that the control is exempt from ancestor
  2440. * calculations of validity or value.
  2441. *
  2442. * @see `markAsDisabled`
  2443. * @see `status`
  2444. */
  2445. var DISABLED = 'DISABLED';
  2446. function _find(control, path, delimiter) {
  2447. if (path == null)
  2448. return null;
  2449. if (!(path instanceof Array)) {
  2450. path = path.split(delimiter);
  2451. }
  2452. if (path instanceof Array && (path.length === 0))
  2453. return null;
  2454. return path.reduce(function (v, name) {
  2455. if (v instanceof FormGroup) {
  2456. return v.controls.hasOwnProperty(name) ? v.controls[name] : null;
  2457. }
  2458. if (v instanceof FormArray) {
  2459. return v.at(name) || null;
  2460. }
  2461. return null;
  2462. }, control);
  2463. }
  2464. function coerceToValidator(validatorOrOpts) {
  2465. var validator = (isOptionsObj(validatorOrOpts) ? validatorOrOpts.validators :
  2466. validatorOrOpts);
  2467. return Array.isArray(validator) ? composeValidators(validator) : validator || null;
  2468. }
  2469. function coerceToAsyncValidator(asyncValidator, validatorOrOpts) {
  2470. var origAsyncValidator = (isOptionsObj(validatorOrOpts) ? validatorOrOpts.asyncValidators :
  2471. asyncValidator);
  2472. return Array.isArray(origAsyncValidator) ? composeAsyncValidators(origAsyncValidator) :
  2473. origAsyncValidator || null;
  2474. }
  2475. function isOptionsObj(validatorOrOpts) {
  2476. return validatorOrOpts != null && !Array.isArray(validatorOrOpts) &&
  2477. typeof validatorOrOpts === 'object';
  2478. }
  2479. /**
  2480. * This is the base class for `FormControl`, `FormGroup`, and `FormArray`.
  2481. *
  2482. * It provides some of the shared behavior that all controls and groups of controls have, like
  2483. * running validators, calculating status, and resetting state. It also defines the properties
  2484. * that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
  2485. * instantiated directly.
  2486. *
  2487. * @see [Forms Guide](/guide/forms)
  2488. * @see [Reactive Forms Guide](/guide/reactive-forms)
  2489. * @see [Dynamic Forms Guide](/guide/dynamic-form)
  2490. *
  2491. * @publicApi
  2492. */
  2493. var AbstractControl = /** @class */ (function () {
  2494. /**
  2495. * Initialize the AbstractControl instance.
  2496. *
  2497. * @param validator The function that determines the synchronous validity of this control.
  2498. * @param asyncValidator The function that determines the asynchronous validity of this
  2499. * control.
  2500. */
  2501. function AbstractControl(validator, asyncValidator) {
  2502. this.validator = validator;
  2503. this.asyncValidator = asyncValidator;
  2504. /** @internal */
  2505. this._onCollectionChange = function () { };
  2506. /**
  2507. * A control is `pristine` if the user has not yet changed
  2508. * the value in the UI.
  2509. *
  2510. * @returns True if the user has not yet changed the value in the UI; compare `dirty`.
  2511. * Programmatic changes to a control's value do not mark it dirty.
  2512. */
  2513. this.pristine = true;
  2514. /**
  2515. * True if the control is marked as `touched`.
  2516. *
  2517. * A control is marked `touched` once the user has triggered
  2518. * a `blur` event on it.
  2519. */
  2520. this.touched = false;
  2521. /** @internal */
  2522. this._onDisabledChange = [];
  2523. }
  2524. Object.defineProperty(AbstractControl.prototype, "parent", {
  2525. /**
  2526. * The parent control.
  2527. */
  2528. get: function () { return this._parent; },
  2529. enumerable: true,
  2530. configurable: true
  2531. });
  2532. Object.defineProperty(AbstractControl.prototype, "valid", {
  2533. /**
  2534. * A control is `valid` when its `status` is `VALID`.
  2535. *
  2536. * @see {@link AbstractControl.status}
  2537. *
  2538. * @returns True if the control has passed all of its validation tests,
  2539. * false otherwise.
  2540. */
  2541. get: function () { return this.status === VALID; },
  2542. enumerable: true,
  2543. configurable: true
  2544. });
  2545. Object.defineProperty(AbstractControl.prototype, "invalid", {
  2546. /**
  2547. * A control is `invalid` when its `status` is `INVALID`.
  2548. *
  2549. * @see {@link AbstractControl.status}
  2550. *
  2551. * @returns True if this control has failed one or more of its validation checks,
  2552. * false otherwise.
  2553. */
  2554. get: function () { return this.status === INVALID; },
  2555. enumerable: true,
  2556. configurable: true
  2557. });
  2558. Object.defineProperty(AbstractControl.prototype, "pending", {
  2559. /**
  2560. * A control is `pending` when its `status` is `PENDING`.
  2561. *
  2562. * @see {@link AbstractControl.status}
  2563. *
  2564. * @returns True if this control is in the process of conducting a validation check,
  2565. * false otherwise.
  2566. */
  2567. get: function () { return this.status == PENDING; },
  2568. enumerable: true,
  2569. configurable: true
  2570. });
  2571. Object.defineProperty(AbstractControl.prototype, "disabled", {
  2572. /**
  2573. * A control is `disabled` when its `status` is `DISABLED`.
  2574. *
  2575. * Disabled controls are exempt from validation checks and
  2576. * are not included in the aggregate value of their ancestor
  2577. * controls.
  2578. *
  2579. * @see {@link AbstractControl.status}
  2580. *
  2581. * @returns True if the control is disabled, false otherwise.
  2582. */
  2583. get: function () { return this.status === DISABLED; },
  2584. enumerable: true,
  2585. configurable: true
  2586. });
  2587. Object.defineProperty(AbstractControl.prototype, "enabled", {
  2588. /**
  2589. * A control is `enabled` as long as its `status` is not `DISABLED`.
  2590. *
  2591. * @returns True if the control has any status other than 'DISABLED',
  2592. * false if the status is 'DISABLED'.
  2593. *
  2594. * @see {@link AbstractControl.status}
  2595. *
  2596. */
  2597. get: function () { return this.status !== DISABLED; },
  2598. enumerable: true,
  2599. configurable: true
  2600. });
  2601. Object.defineProperty(AbstractControl.prototype, "dirty", {
  2602. /**
  2603. * A control is `dirty` if the user has changed the value
  2604. * in the UI.
  2605. *
  2606. * @returns True if the user has changed the value of this control in the UI; compare `pristine`.
  2607. * Programmatic changes to a control's value do not mark it dirty.
  2608. */
  2609. get: function () { return !this.pristine; },
  2610. enumerable: true,
  2611. configurable: true
  2612. });
  2613. Object.defineProperty(AbstractControl.prototype, "untouched", {
  2614. /**
  2615. * True if the control has not been marked as touched
  2616. *
  2617. * A control is `untouched` if the user has not yet triggered
  2618. * a `blur` event on it.
  2619. */
  2620. get: function () { return !this.touched; },
  2621. enumerable: true,
  2622. configurable: true
  2623. });
  2624. Object.defineProperty(AbstractControl.prototype, "updateOn", {
  2625. /**
  2626. * Reports the update strategy of the `AbstractControl` (meaning
  2627. * the event on which the control updates itself).
  2628. * Possible values: `'change'` | `'blur'` | `'submit'`
  2629. * Default value: `'change'`
  2630. */
  2631. get: function () {
  2632. return this._updateOn ? this._updateOn : (this.parent ? this.parent.updateOn : 'change');
  2633. },
  2634. enumerable: true,
  2635. configurable: true
  2636. });
  2637. /**
  2638. * Sets the synchronous validators that are active on this control. Calling
  2639. * this overwrites any existing sync validators.
  2640. */
  2641. AbstractControl.prototype.setValidators = function (newValidator) {
  2642. this.validator = coerceToValidator(newValidator);
  2643. };
  2644. /**
  2645. * Sets the async validators that are active on this control. Calling this
  2646. * overwrites any existing async validators.
  2647. */
  2648. AbstractControl.prototype.setAsyncValidators = function (newValidator) {
  2649. this.asyncValidator = coerceToAsyncValidator(newValidator);
  2650. };
  2651. /**
  2652. * Empties out the sync validator list.
  2653. */
  2654. AbstractControl.prototype.clearValidators = function () { this.validator = null; };
  2655. /**
  2656. * Empties out the async validator list.
  2657. */
  2658. AbstractControl.prototype.clearAsyncValidators = function () { this.asyncValidator = null; };
  2659. /**
  2660. * Marks the control as `touched`. A control is touched by focus and
  2661. * blur events that do not change the value.
  2662. *
  2663. * @see `markAsUntouched()`
  2664. * @see `markAsDirty()`
  2665. * @see `markAsPristine()`
  2666. *
  2667. * @param opts Configuration options that determine how the control propagates changes
  2668. * and emits events events after marking is applied.
  2669. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2670. * marks all direct ancestors. Default is false.
  2671. */
  2672. AbstractControl.prototype.markAsTouched = function (opts) {
  2673. if (opts === void 0) { opts = {}; }
  2674. this.touched = true;
  2675. if (this._parent && !opts.onlySelf) {
  2676. this._parent.markAsTouched(opts);
  2677. }
  2678. };
  2679. /**
  2680. * Marks the control and all its descendant controls as `touched`.
  2681. * @see `markAsTouched()`
  2682. */
  2683. AbstractControl.prototype.markAllAsTouched = function () {
  2684. this.markAsTouched({ onlySelf: true });
  2685. this._forEachChild(function (control) { return control.markAllAsTouched(); });
  2686. };
  2687. /**
  2688. * Marks the control as `untouched`.
  2689. *
  2690. * If the control has any children, also marks all children as `untouched`
  2691. * and recalculates the `touched` status of all parent controls.
  2692. *
  2693. * @see `markAsTouched()`
  2694. * @see `markAsDirty()`
  2695. * @see `markAsPristine()`
  2696. *
  2697. * @param opts Configuration options that determine how the control propagates changes
  2698. * and emits events after the marking is applied.
  2699. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2700. * marks all direct ancestors. Default is false.
  2701. */
  2702. AbstractControl.prototype.markAsUntouched = function (opts) {
  2703. if (opts === void 0) { opts = {}; }
  2704. this.touched = false;
  2705. this._pendingTouched = false;
  2706. this._forEachChild(function (control) { control.markAsUntouched({ onlySelf: true }); });
  2707. if (this._parent && !opts.onlySelf) {
  2708. this._parent._updateTouched(opts);
  2709. }
  2710. };
  2711. /**
  2712. * Marks the control as `dirty`. A control becomes dirty when
  2713. * the control's value is changed through the UI; compare `markAsTouched`.
  2714. *
  2715. * @see `markAsTouched()`
  2716. * @see `markAsUntouched()`
  2717. * @see `markAsPristine()`
  2718. *
  2719. * @param opts Configuration options that determine how the control propagates changes
  2720. * and emits events after marking is applied.
  2721. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2722. * marks all direct ancestors. Default is false.
  2723. */
  2724. AbstractControl.prototype.markAsDirty = function (opts) {
  2725. if (opts === void 0) { opts = {}; }
  2726. this.pristine = false;
  2727. if (this._parent && !opts.onlySelf) {
  2728. this._parent.markAsDirty(opts);
  2729. }
  2730. };
  2731. /**
  2732. * Marks the control as `pristine`.
  2733. *
  2734. * If the control has any children, marks all children as `pristine`,
  2735. * and recalculates the `pristine` status of all parent
  2736. * controls.
  2737. *
  2738. * @see `markAsTouched()`
  2739. * @see `markAsUntouched()`
  2740. * @see `markAsDirty()`
  2741. *
  2742. * @param opts Configuration options that determine how the control emits events after
  2743. * marking is applied.
  2744. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2745. * marks all direct ancestors. Default is false..
  2746. */
  2747. AbstractControl.prototype.markAsPristine = function (opts) {
  2748. if (opts === void 0) { opts = {}; }
  2749. this.pristine = true;
  2750. this._pendingDirty = false;
  2751. this._forEachChild(function (control) { control.markAsPristine({ onlySelf: true }); });
  2752. if (this._parent && !opts.onlySelf) {
  2753. this._parent._updatePristine(opts);
  2754. }
  2755. };
  2756. /**
  2757. * Marks the control as `pending`.
  2758. *
  2759. * A control is pending while the control performs async validation.
  2760. *
  2761. * @see {@link AbstractControl.status}
  2762. *
  2763. * @param opts Configuration options that determine how the control propagates changes and
  2764. * emits events after marking is applied.
  2765. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2766. * marks all direct ancestors. Default is false..
  2767. * * `emitEvent`: When true or not supplied (the default), the `statusChanges`
  2768. * observable emits an event with the latest status the control is marked pending.
  2769. * When false, no events are emitted.
  2770. *
  2771. */
  2772. AbstractControl.prototype.markAsPending = function (opts) {
  2773. if (opts === void 0) { opts = {}; }
  2774. this.status = PENDING;
  2775. if (opts.emitEvent !== false) {
  2776. this.statusChanges.emit(this.status);
  2777. }
  2778. if (this._parent && !opts.onlySelf) {
  2779. this._parent.markAsPending(opts);
  2780. }
  2781. };
  2782. /**
  2783. * Disables the control. This means the control is exempt from validation checks and
  2784. * excluded from the aggregate value of any parent. Its status is `DISABLED`.
  2785. *
  2786. * If the control has children, all children are also disabled.
  2787. *
  2788. * @see {@link AbstractControl.status}
  2789. *
  2790. * @param opts Configuration options that determine how the control propagates
  2791. * changes and emits events after the control is disabled.
  2792. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2793. * marks all direct ancestors. Default is false..
  2794. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2795. * `valueChanges`
  2796. * observables emit events with the latest status and value when the control is disabled.
  2797. * When false, no events are emitted.
  2798. */
  2799. AbstractControl.prototype.disable = function (opts) {
  2800. if (opts === void 0) { opts = {}; }
  2801. // If parent has been marked artificially dirty we don't want to re-calculate the
  2802. // parent's dirtiness based on the children.
  2803. var skipPristineCheck = this._parentMarkedDirty(opts.onlySelf);
  2804. this.status = DISABLED;
  2805. this.errors = null;
  2806. this._forEachChild(function (control) { control.disable(__assign({}, opts, { onlySelf: true })); });
  2807. this._updateValue();
  2808. if (opts.emitEvent !== false) {
  2809. this.valueChanges.emit(this.value);
  2810. this.statusChanges.emit(this.status);
  2811. }
  2812. this._updateAncestors(__assign({}, opts, { skipPristineCheck: skipPristineCheck }));
  2813. this._onDisabledChange.forEach(function (changeFn) { return changeFn(true); });
  2814. };
  2815. /**
  2816. * Enables the control. This means the control is included in validation checks and
  2817. * the aggregate value of its parent. Its status recalculates based on its value and
  2818. * its validators.
  2819. *
  2820. * By default, if the control has children, all children are enabled.
  2821. *
  2822. * @see {@link AbstractControl.status}
  2823. *
  2824. * @param opts Configure options that control how the control propagates changes and
  2825. * emits events when marked as untouched
  2826. * * `onlySelf`: When true, mark only this control. When false or not supplied,
  2827. * marks all direct ancestors. Default is false..
  2828. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2829. * `valueChanges`
  2830. * observables emit events with the latest status and value when the control is enabled.
  2831. * When false, no events are emitted.
  2832. */
  2833. AbstractControl.prototype.enable = function (opts) {
  2834. if (opts === void 0) { opts = {}; }
  2835. // If parent has been marked artificially dirty we don't want to re-calculate the
  2836. // parent's dirtiness based on the children.
  2837. var skipPristineCheck = this._parentMarkedDirty(opts.onlySelf);
  2838. this.status = VALID;
  2839. this._forEachChild(function (control) { control.enable(__assign({}, opts, { onlySelf: true })); });
  2840. this.updateValueAndValidity({ onlySelf: true, emitEvent: opts.emitEvent });
  2841. this._updateAncestors(__assign({}, opts, { skipPristineCheck: skipPristineCheck }));
  2842. this._onDisabledChange.forEach(function (changeFn) { return changeFn(false); });
  2843. };
  2844. AbstractControl.prototype._updateAncestors = function (opts) {
  2845. if (this._parent && !opts.onlySelf) {
  2846. this._parent.updateValueAndValidity(opts);
  2847. if (!opts.skipPristineCheck) {
  2848. this._parent._updatePristine();
  2849. }
  2850. this._parent._updateTouched();
  2851. }
  2852. };
  2853. /**
  2854. * @param parent Sets the parent of the control
  2855. */
  2856. AbstractControl.prototype.setParent = function (parent) { this._parent = parent; };
  2857. /**
  2858. * Recalculates the value and validation status of the control.
  2859. *
  2860. * By default, it also updates the value and validity of its ancestors.
  2861. *
  2862. * @param opts Configuration options determine how the control propagates changes and emits events
  2863. * after updates and validity checks are applied.
  2864. * * `onlySelf`: When true, only update this control. When false or not supplied,
  2865. * update all direct ancestors. Default is false..
  2866. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  2867. * `valueChanges`
  2868. * observables emit events with the latest status and value when the control is updated.
  2869. * When false, no events are emitted.
  2870. */
  2871. AbstractControl.prototype.updateValueAndValidity = function (opts) {
  2872. if (opts === void 0) { opts = {}; }
  2873. this._setInitialStatus();
  2874. this._updateValue();
  2875. if (this.enabled) {
  2876. this._cancelExistingSubscription();
  2877. this.errors = this._runValidator();
  2878. this.status = this._calculateStatus();
  2879. if (this.status === VALID || this.status === PENDING) {
  2880. this._runAsyncValidator(opts.emitEvent);
  2881. }
  2882. }
  2883. if (opts.emitEvent !== false) {
  2884. this.valueChanges.emit(this.value);
  2885. this.statusChanges.emit(this.status);
  2886. }
  2887. if (this._parent && !opts.onlySelf) {
  2888. this._parent.updateValueAndValidity(opts);
  2889. }
  2890. };
  2891. /** @internal */
  2892. AbstractControl.prototype._updateTreeValidity = function (opts) {
  2893. if (opts === void 0) { opts = { emitEvent: true }; }
  2894. this._forEachChild(function (ctrl) { return ctrl._updateTreeValidity(opts); });
  2895. this.updateValueAndValidity({ onlySelf: true, emitEvent: opts.emitEvent });
  2896. };
  2897. AbstractControl.prototype._setInitialStatus = function () {
  2898. this.status = this._allControlsDisabled() ? DISABLED : VALID;
  2899. };
  2900. AbstractControl.prototype._runValidator = function () {
  2901. return this.validator ? this.validator(this) : null;
  2902. };
  2903. AbstractControl.prototype._runAsyncValidator = function (emitEvent) {
  2904. var _this = this;
  2905. if (this.asyncValidator) {
  2906. this.status = PENDING;
  2907. var obs = toObservable(this.asyncValidator(this));
  2908. this._asyncValidationSubscription =
  2909. obs.subscribe(function (errors) { return _this.setErrors(errors, { emitEvent: emitEvent }); });
  2910. }
  2911. };
  2912. AbstractControl.prototype._cancelExistingSubscription = function () {
  2913. if (this._asyncValidationSubscription) {
  2914. this._asyncValidationSubscription.unsubscribe();
  2915. }
  2916. };
  2917. /**
  2918. * Sets errors on a form control when running validations manually, rather than automatically.
  2919. *
  2920. * Calling `setErrors` also updates the validity of the parent control.
  2921. *
  2922. * @usageNotes
  2923. * ### Manually set the errors for a control
  2924. *
  2925. * ```
  2926. * const login = new FormControl('someLogin');
  2927. * login.setErrors({
  2928. * notUnique: true
  2929. * });
  2930. *
  2931. * expect(login.valid).toEqual(false);
  2932. * expect(login.errors).toEqual({ notUnique: true });
  2933. *
  2934. * login.setValue('someOtherLogin');
  2935. *
  2936. * expect(login.valid).toEqual(true);
  2937. * ```
  2938. */
  2939. AbstractControl.prototype.setErrors = function (errors, opts) {
  2940. if (opts === void 0) { opts = {}; }
  2941. this.errors = errors;
  2942. this._updateControlsErrors(opts.emitEvent !== false);
  2943. };
  2944. /**
  2945. * Retrieves a child control given the control's name or path.
  2946. *
  2947. * @param path A dot-delimited string or array of string/number values that define the path to the
  2948. * control.
  2949. *
  2950. * @usageNotes
  2951. * ### Retrieve a nested control
  2952. *
  2953. * For example, to get a `name` control nested within a `person` sub-group:
  2954. *
  2955. * * `this.form.get('person.name');`
  2956. *
  2957. * -OR-
  2958. *
  2959. * * `this.form.get(['person', 'name']);`
  2960. */
  2961. AbstractControl.prototype.get = function (path) { return _find(this, path, '.'); };
  2962. /**
  2963. * @description
  2964. * Reports error data for the control with the given path.
  2965. *
  2966. * @param errorCode The code of the error to check
  2967. * @param path A list of control names that designates how to move from the current control
  2968. * to the control that should be queried for errors.
  2969. *
  2970. * @usageNotes
  2971. * For example, for the following `FormGroup`:
  2972. *
  2973. * ```
  2974. * form = new FormGroup({
  2975. * address: new FormGroup({ street: new FormControl() })
  2976. * });
  2977. * ```
  2978. *
  2979. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  2980. *
  2981. * It can be provided to this method in one of two formats:
  2982. *
  2983. * 1. An array of string control names, e.g. `['address', 'street']`
  2984. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  2985. *
  2986. * @returns error data for that particular error. If the control or error is not present,
  2987. * null is returned.
  2988. */
  2989. AbstractControl.prototype.getError = function (errorCode, path) {
  2990. var control = path ? this.get(path) : this;
  2991. return control && control.errors ? control.errors[errorCode] : null;
  2992. };
  2993. /**
  2994. * @description
  2995. * Reports whether the control with the given path has the error specified.
  2996. *
  2997. * @param errorCode The code of the error to check
  2998. * @param path A list of control names that designates how to move from the current control
  2999. * to the control that should be queried for errors.
  3000. *
  3001. * @usageNotes
  3002. * For example, for the following `FormGroup`:
  3003. *
  3004. * ```
  3005. * form = new FormGroup({
  3006. * address: new FormGroup({ street: new FormControl() })
  3007. * });
  3008. * ```
  3009. *
  3010. * The path to the 'street' control from the root form would be 'address' -> 'street'.
  3011. *
  3012. * It can be provided to this method in one of two formats:
  3013. *
  3014. * 1. An array of string control names, e.g. `['address', 'street']`
  3015. * 1. A period-delimited list of control names in one string, e.g. `'address.street'`
  3016. *
  3017. * If no path is given, this method checks for the error on the current control.
  3018. *
  3019. * @returns whether the given error is present in the control at the given path.
  3020. *
  3021. * If the control is not present, false is returned.
  3022. */
  3023. AbstractControl.prototype.hasError = function (errorCode, path) {
  3024. return !!this.getError(errorCode, path);
  3025. };
  3026. Object.defineProperty(AbstractControl.prototype, "root", {
  3027. /**
  3028. * Retrieves the top-level ancestor of this control.
  3029. */
  3030. get: function () {
  3031. var x = this;
  3032. while (x._parent) {
  3033. x = x._parent;
  3034. }
  3035. return x;
  3036. },
  3037. enumerable: true,
  3038. configurable: true
  3039. });
  3040. /** @internal */
  3041. AbstractControl.prototype._updateControlsErrors = function (emitEvent) {
  3042. this.status = this._calculateStatus();
  3043. if (emitEvent) {
  3044. this.statusChanges.emit(this.status);
  3045. }
  3046. if (this._parent) {
  3047. this._parent._updateControlsErrors(emitEvent);
  3048. }
  3049. };
  3050. /** @internal */
  3051. AbstractControl.prototype._initObservables = function () {
  3052. this.valueChanges = new core.EventEmitter();
  3053. this.statusChanges = new core.EventEmitter();
  3054. };
  3055. AbstractControl.prototype._calculateStatus = function () {
  3056. if (this._allControlsDisabled())
  3057. return DISABLED;
  3058. if (this.errors)
  3059. return INVALID;
  3060. if (this._anyControlsHaveStatus(PENDING))
  3061. return PENDING;
  3062. if (this._anyControlsHaveStatus(INVALID))
  3063. return INVALID;
  3064. return VALID;
  3065. };
  3066. /** @internal */
  3067. AbstractControl.prototype._anyControlsHaveStatus = function (status) {
  3068. return this._anyControls(function (control) { return control.status === status; });
  3069. };
  3070. /** @internal */
  3071. AbstractControl.prototype._anyControlsDirty = function () {
  3072. return this._anyControls(function (control) { return control.dirty; });
  3073. };
  3074. /** @internal */
  3075. AbstractControl.prototype._anyControlsTouched = function () {
  3076. return this._anyControls(function (control) { return control.touched; });
  3077. };
  3078. /** @internal */
  3079. AbstractControl.prototype._updatePristine = function (opts) {
  3080. if (opts === void 0) { opts = {}; }
  3081. this.pristine = !this._anyControlsDirty();
  3082. if (this._parent && !opts.onlySelf) {
  3083. this._parent._updatePristine(opts);
  3084. }
  3085. };
  3086. /** @internal */
  3087. AbstractControl.prototype._updateTouched = function (opts) {
  3088. if (opts === void 0) { opts = {}; }
  3089. this.touched = this._anyControlsTouched();
  3090. if (this._parent && !opts.onlySelf) {
  3091. this._parent._updateTouched(opts);
  3092. }
  3093. };
  3094. /** @internal */
  3095. AbstractControl.prototype._isBoxedValue = function (formState) {
  3096. return typeof formState === 'object' && formState !== null &&
  3097. Object.keys(formState).length === 2 && 'value' in formState && 'disabled' in formState;
  3098. };
  3099. /** @internal */
  3100. AbstractControl.prototype._registerOnCollectionChange = function (fn) { this._onCollectionChange = fn; };
  3101. /** @internal */
  3102. AbstractControl.prototype._setUpdateStrategy = function (opts) {
  3103. if (isOptionsObj(opts) && opts.updateOn != null) {
  3104. this._updateOn = opts.updateOn;
  3105. }
  3106. };
  3107. /**
  3108. * Check to see if parent has been marked artificially dirty.
  3109. *
  3110. * @internal
  3111. */
  3112. AbstractControl.prototype._parentMarkedDirty = function (onlySelf) {
  3113. var parentDirty = this._parent && this._parent.dirty;
  3114. return !onlySelf && parentDirty && !this._parent._anyControlsDirty();
  3115. };
  3116. return AbstractControl;
  3117. }());
  3118. /**
  3119. * Tracks the value and validation status of an individual form control.
  3120. *
  3121. * This is one of the three fundamental building blocks of Angular forms, along with
  3122. * `FormGroup` and `FormArray`. It extends the `AbstractControl` class that
  3123. * implements most of the base functionality for accessing the value, validation status,
  3124. * user interactions and events.
  3125. *
  3126. * @see `AbstractControl`
  3127. * @see [Reactive Forms Guide](guide/reactive-forms)
  3128. * @see [Usage Notes](#usage-notes)
  3129. *
  3130. * @usageNotes
  3131. *
  3132. * ### Initializing Form Controls
  3133. *
  3134. * Instantiate a `FormControl`, with an initial value.
  3135. *
  3136. * ```ts
  3137. * const control = new FormControl('some value');
  3138. * console.log(control.value); // 'some value'
  3139. *```
  3140. *
  3141. * The following example initializes the control with a form state object. The `value`
  3142. * and `disabled` keys are required in this case.
  3143. *
  3144. * ```ts
  3145. * const control = new FormControl({ value: 'n/a', disabled: true });
  3146. * console.log(control.value); // 'n/a'
  3147. * console.log(control.status); // 'DISABLED'
  3148. * ```
  3149. *
  3150. * The following example initializes the control with a sync validator.
  3151. *
  3152. * ```ts
  3153. * const control = new FormControl('', Validators.required);
  3154. * console.log(control.value); // ''
  3155. * console.log(control.status); // 'INVALID'
  3156. * ```
  3157. *
  3158. * The following example initializes the control using an options object.
  3159. *
  3160. * ```ts
  3161. * const control = new FormControl('', {
  3162. * validators: Validators.required,
  3163. * asyncValidators: myAsyncValidator
  3164. * });
  3165. * ```
  3166. *
  3167. * ### Configure the control to update on a blur event
  3168. *
  3169. * Set the `updateOn` option to `'blur'` to update on the blur `event`.
  3170. *
  3171. * ```ts
  3172. * const control = new FormControl('', { updateOn: 'blur' });
  3173. * ```
  3174. *
  3175. * ### Configure the control to update on a submit event
  3176. *
  3177. * Set the `updateOn` option to `'submit'` to update on a submit `event`.
  3178. *
  3179. * ```ts
  3180. * const control = new FormControl('', { updateOn: 'submit' });
  3181. * ```
  3182. *
  3183. * ### Reset the control back to an initial value
  3184. *
  3185. * You reset to a specific form state by passing through a standalone
  3186. * value or a form state object that contains both a value and a disabled state
  3187. * (these are the only two properties that cannot be calculated).
  3188. *
  3189. * ```ts
  3190. * const control = new FormControl('Nancy');
  3191. *
  3192. * console.log(control.value); // 'Nancy'
  3193. *
  3194. * control.reset('Drew');
  3195. *
  3196. * console.log(control.value); // 'Drew'
  3197. * ```
  3198. *
  3199. * ### Reset the control back to an initial value and disabled
  3200. *
  3201. * ```
  3202. * const control = new FormControl('Nancy');
  3203. *
  3204. * console.log(control.value); // 'Nancy'
  3205. * console.log(control.status); // 'VALID'
  3206. *
  3207. * control.reset({ value: 'Drew', disabled: true });
  3208. *
  3209. * console.log(control.value); // 'Drew'
  3210. * console.log(control.status); // 'DISABLED'
  3211. * ```
  3212. *
  3213. * @publicApi
  3214. */
  3215. var FormControl = /** @class */ (function (_super) {
  3216. __extends(FormControl, _super);
  3217. /**
  3218. * Creates a new `FormControl` instance.
  3219. *
  3220. * @param formState Initializes the control with an initial value,
  3221. * or an object that defines the initial value and disabled state.
  3222. *
  3223. * @param validatorOrOpts A synchronous validator function, or an array of
  3224. * such functions, or an `AbstractControlOptions` object that contains validation functions
  3225. * and a validation trigger.
  3226. *
  3227. * @param asyncValidator A single async validator or array of async validator functions
  3228. *
  3229. */
  3230. function FormControl(formState, validatorOrOpts, asyncValidator) {
  3231. if (formState === void 0) { formState = null; }
  3232. var _this = _super.call(this, coerceToValidator(validatorOrOpts), coerceToAsyncValidator(asyncValidator, validatorOrOpts)) || this;
  3233. /** @internal */
  3234. _this._onChange = [];
  3235. _this._applyFormState(formState);
  3236. _this._setUpdateStrategy(validatorOrOpts);
  3237. _this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
  3238. _this._initObservables();
  3239. return _this;
  3240. }
  3241. /**
  3242. * Sets a new value for the form control.
  3243. *
  3244. * @param value The new value for the control.
  3245. * @param options Configuration options that determine how the control propagates changes
  3246. * and emits events when the value changes.
  3247. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  3248. * updateValueAndValidity} method.
  3249. *
  3250. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  3251. * false.
  3252. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3253. * `valueChanges`
  3254. * observables emit events with the latest status and value when the control value is updated.
  3255. * When false, no events are emitted.
  3256. * * `emitModelToViewChange`: When true or not supplied (the default), each change triggers an
  3257. * `onChange` event to
  3258. * update the view.
  3259. * * `emitViewToModelChange`: When true or not supplied (the default), each change triggers an
  3260. * `ngModelChange`
  3261. * event to update the model.
  3262. *
  3263. */
  3264. FormControl.prototype.setValue = function (value, options) {
  3265. var _this = this;
  3266. if (options === void 0) { options = {}; }
  3267. this.value = this._pendingValue = value;
  3268. if (this._onChange.length && options.emitModelToViewChange !== false) {
  3269. this._onChange.forEach(function (changeFn) { return changeFn(_this.value, options.emitViewToModelChange !== false); });
  3270. }
  3271. this.updateValueAndValidity(options);
  3272. };
  3273. /**
  3274. * Patches the value of a control.
  3275. *
  3276. * This function is functionally the same as {@link FormControl#setValue setValue} at this level.
  3277. * It exists for symmetry with {@link FormGroup#patchValue patchValue} on `FormGroups` and
  3278. * `FormArrays`, where it does behave differently.
  3279. *
  3280. * @see `setValue` for options
  3281. */
  3282. FormControl.prototype.patchValue = function (value, options) {
  3283. if (options === void 0) { options = {}; }
  3284. this.setValue(value, options);
  3285. };
  3286. /**
  3287. * Resets the form control, marking it `pristine` and `untouched`, and setting
  3288. * the value to null.
  3289. *
  3290. * @param formState Resets the control with an initial value,
  3291. * or an object that defines the initial value and disabled state.
  3292. *
  3293. * @param options Configuration options that determine how the control propagates changes
  3294. * and emits events after the value changes.
  3295. *
  3296. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  3297. * false.
  3298. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3299. * `valueChanges`
  3300. * observables emit events with the latest status and value when the control is reset.
  3301. * When false, no events are emitted.
  3302. *
  3303. */
  3304. FormControl.prototype.reset = function (formState, options) {
  3305. if (formState === void 0) { formState = null; }
  3306. if (options === void 0) { options = {}; }
  3307. this._applyFormState(formState);
  3308. this.markAsPristine(options);
  3309. this.markAsUntouched(options);
  3310. this.setValue(this.value, options);
  3311. this._pendingChange = false;
  3312. };
  3313. /**
  3314. * @internal
  3315. */
  3316. FormControl.prototype._updateValue = function () { };
  3317. /**
  3318. * @internal
  3319. */
  3320. FormControl.prototype._anyControls = function (condition) { return false; };
  3321. /**
  3322. * @internal
  3323. */
  3324. FormControl.prototype._allControlsDisabled = function () { return this.disabled; };
  3325. /**
  3326. * Register a listener for change events.
  3327. *
  3328. * @param fn The method that is called when the value changes
  3329. */
  3330. FormControl.prototype.registerOnChange = function (fn) { this._onChange.push(fn); };
  3331. /**
  3332. * @internal
  3333. */
  3334. FormControl.prototype._clearChangeFns = function () {
  3335. this._onChange = [];
  3336. this._onDisabledChange = [];
  3337. this._onCollectionChange = function () { };
  3338. };
  3339. /**
  3340. * Register a listener for disabled events.
  3341. *
  3342. * @param fn The method that is called when the disabled status changes.
  3343. */
  3344. FormControl.prototype.registerOnDisabledChange = function (fn) {
  3345. this._onDisabledChange.push(fn);
  3346. };
  3347. /**
  3348. * @internal
  3349. */
  3350. FormControl.prototype._forEachChild = function (cb) { };
  3351. /** @internal */
  3352. FormControl.prototype._syncPendingControls = function () {
  3353. if (this.updateOn === 'submit') {
  3354. if (this._pendingDirty)
  3355. this.markAsDirty();
  3356. if (this._pendingTouched)
  3357. this.markAsTouched();
  3358. if (this._pendingChange) {
  3359. this.setValue(this._pendingValue, { onlySelf: true, emitModelToViewChange: false });
  3360. return true;
  3361. }
  3362. }
  3363. return false;
  3364. };
  3365. FormControl.prototype._applyFormState = function (formState) {
  3366. if (this._isBoxedValue(formState)) {
  3367. this.value = this._pendingValue = formState.value;
  3368. formState.disabled ? this.disable({ onlySelf: true, emitEvent: false }) :
  3369. this.enable({ onlySelf: true, emitEvent: false });
  3370. }
  3371. else {
  3372. this.value = this._pendingValue = formState;
  3373. }
  3374. };
  3375. return FormControl;
  3376. }(AbstractControl));
  3377. /**
  3378. * Tracks the value and validity state of a group of `FormControl` instances.
  3379. *
  3380. * A `FormGroup` aggregates the values of each child `FormControl` into one object,
  3381. * with each control name as the key. It calculates its status by reducing the status values
  3382. * of its children. For example, if one of the controls in a group is invalid, the entire
  3383. * group becomes invalid.
  3384. *
  3385. * `FormGroup` is one of the three fundamental building blocks used to define forms in Angular,
  3386. * along with `FormControl` and `FormArray`.
  3387. *
  3388. * When instantiating a `FormGroup`, pass in a collection of child controls as the first
  3389. * argument. The key for each child registers the name for the control.
  3390. *
  3391. * @usageNotes
  3392. *
  3393. * ### Create a form group with 2 controls
  3394. *
  3395. * ```
  3396. * const form = new FormGroup({
  3397. * first: new FormControl('Nancy', Validators.minLength(2)),
  3398. * last: new FormControl('Drew'),
  3399. * });
  3400. *
  3401. * console.log(form.value); // {first: 'Nancy', last; 'Drew'}
  3402. * console.log(form.status); // 'VALID'
  3403. * ```
  3404. *
  3405. * ### Create a form group with a group-level validator
  3406. *
  3407. * You include group-level validators as the second arg, or group-level async
  3408. * validators as the third arg. These come in handy when you want to perform validation
  3409. * that considers the value of more than one child control.
  3410. *
  3411. * ```
  3412. * const form = new FormGroup({
  3413. * password: new FormControl('', Validators.minLength(2)),
  3414. * passwordConfirm: new FormControl('', Validators.minLength(2)),
  3415. * }, passwordMatchValidator);
  3416. *
  3417. *
  3418. * function passwordMatchValidator(g: FormGroup) {
  3419. * return g.get('password').value === g.get('passwordConfirm').value
  3420. * ? null : {'mismatch': true};
  3421. * }
  3422. * ```
  3423. *
  3424. * Like `FormControl` instances, you choose to pass in
  3425. * validators and async validators as part of an options object.
  3426. *
  3427. * ```
  3428. * const form = new FormGroup({
  3429. * password: new FormControl('')
  3430. * passwordConfirm: new FormControl('')
  3431. * }, { validators: passwordMatchValidator, asyncValidators: otherValidator });
  3432. * ```
  3433. *
  3434. * ### Set the updateOn property for all controls in a form group
  3435. *
  3436. * The options object is used to set a default value for each child
  3437. * control's `updateOn` property. If you set `updateOn` to `'blur'` at the
  3438. * group level, all child controls default to 'blur', unless the child
  3439. * has explicitly specified a different `updateOn` value.
  3440. *
  3441. * ```ts
  3442. * const c = new FormGroup({
  3443. * one: new FormControl()
  3444. * }, { updateOn: 'blur' });
  3445. * ```
  3446. *
  3447. * @publicApi
  3448. */
  3449. var FormGroup = /** @class */ (function (_super) {
  3450. __extends(FormGroup, _super);
  3451. /**
  3452. * Creates a new `FormGroup` instance.
  3453. *
  3454. * @param controls A collection of child controls. The key for each child is the name
  3455. * under which it is registered.
  3456. *
  3457. * @param validatorOrOpts A synchronous validator function, or an array of
  3458. * such functions, or an `AbstractControlOptions` object that contains validation functions
  3459. * and a validation trigger.
  3460. *
  3461. * @param asyncValidator A single async validator or array of async validator functions
  3462. *
  3463. */
  3464. function FormGroup(controls, validatorOrOpts, asyncValidator) {
  3465. var _this = _super.call(this, coerceToValidator(validatorOrOpts), coerceToAsyncValidator(asyncValidator, validatorOrOpts)) || this;
  3466. _this.controls = controls;
  3467. _this._initObservables();
  3468. _this._setUpdateStrategy(validatorOrOpts);
  3469. _this._setUpControls();
  3470. _this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
  3471. return _this;
  3472. }
  3473. /**
  3474. * Registers a control with the group's list of controls.
  3475. *
  3476. * This method does not update the value or validity of the control.
  3477. * Use {@link FormGroup#addControl addControl} instead.
  3478. *
  3479. * @param name The control name to register in the collection
  3480. * @param control Provides the control for the given name
  3481. */
  3482. FormGroup.prototype.registerControl = function (name, control) {
  3483. if (this.controls[name])
  3484. return this.controls[name];
  3485. this.controls[name] = control;
  3486. control.setParent(this);
  3487. control._registerOnCollectionChange(this._onCollectionChange);
  3488. return control;
  3489. };
  3490. /**
  3491. * Add a control to this group.
  3492. *
  3493. * This method also updates the value and validity of the control.
  3494. *
  3495. * @param name The control name to add to the collection
  3496. * @param control Provides the control for the given name
  3497. */
  3498. FormGroup.prototype.addControl = function (name, control) {
  3499. this.registerControl(name, control);
  3500. this.updateValueAndValidity();
  3501. this._onCollectionChange();
  3502. };
  3503. /**
  3504. * Remove a control from this group.
  3505. *
  3506. * @param name The control name to remove from the collection
  3507. */
  3508. FormGroup.prototype.removeControl = function (name) {
  3509. if (this.controls[name])
  3510. this.controls[name]._registerOnCollectionChange(function () { });
  3511. delete (this.controls[name]);
  3512. this.updateValueAndValidity();
  3513. this._onCollectionChange();
  3514. };
  3515. /**
  3516. * Replace an existing control.
  3517. *
  3518. * @param name The control name to replace in the collection
  3519. * @param control Provides the control for the given name
  3520. */
  3521. FormGroup.prototype.setControl = function (name, control) {
  3522. if (this.controls[name])
  3523. this.controls[name]._registerOnCollectionChange(function () { });
  3524. delete (this.controls[name]);
  3525. if (control)
  3526. this.registerControl(name, control);
  3527. this.updateValueAndValidity();
  3528. this._onCollectionChange();
  3529. };
  3530. /**
  3531. * Check whether there is an enabled control with the given name in the group.
  3532. *
  3533. * Reports false for disabled controls. If you'd like to check for existence in the group
  3534. * only, use {@link AbstractControl#get get} instead.
  3535. *
  3536. * @param name The control name to check for existence in the collection
  3537. *
  3538. * @returns false for disabled controls, true otherwise.
  3539. */
  3540. FormGroup.prototype.contains = function (controlName) {
  3541. return this.controls.hasOwnProperty(controlName) && this.controls[controlName].enabled;
  3542. };
  3543. /**
  3544. * Sets the value of the `FormGroup`. It accepts an object that matches
  3545. * the structure of the group, with control names as keys.
  3546. *
  3547. * @usageNotes
  3548. * ### Set the complete value for the form group
  3549. *
  3550. * ```
  3551. * const form = new FormGroup({
  3552. * first: new FormControl(),
  3553. * last: new FormControl()
  3554. * });
  3555. *
  3556. * console.log(form.value); // {first: null, last: null}
  3557. *
  3558. * form.setValue({first: 'Nancy', last: 'Drew'});
  3559. * console.log(form.value); // {first: 'Nancy', last: 'Drew'}
  3560. * ```
  3561. *
  3562. * @throws When strict checks fail, such as setting the value of a control
  3563. * that doesn't exist or if you excluding the value of a control.
  3564. *
  3565. * @param value The new value for the control that matches the structure of the group.
  3566. * @param options Configuration options that determine how the control propagates changes
  3567. * and emits events after the value changes.
  3568. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  3569. * updateValueAndValidity} method.
  3570. *
  3571. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  3572. * false.
  3573. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3574. * `valueChanges`
  3575. * observables emit events with the latest status and value when the control value is updated.
  3576. * When false, no events are emitted.
  3577. */
  3578. FormGroup.prototype.setValue = function (value, options) {
  3579. var _this = this;
  3580. if (options === void 0) { options = {}; }
  3581. this._checkAllValuesPresent(value);
  3582. Object.keys(value).forEach(function (name) {
  3583. _this._throwIfControlMissing(name);
  3584. _this.controls[name].setValue(value[name], { onlySelf: true, emitEvent: options.emitEvent });
  3585. });
  3586. this.updateValueAndValidity(options);
  3587. };
  3588. /**
  3589. * Patches the value of the `FormGroup`. It accepts an object with control
  3590. * names as keys, and does its best to match the values to the correct controls
  3591. * in the group.
  3592. *
  3593. * It accepts both super-sets and sub-sets of the group without throwing an error.
  3594. *
  3595. * @usageNotes
  3596. * ### Patch the value for a form group
  3597. *
  3598. * ```
  3599. * const form = new FormGroup({
  3600. * first: new FormControl(),
  3601. * last: new FormControl()
  3602. * });
  3603. * console.log(form.value); // {first: null, last: null}
  3604. *
  3605. * form.patchValue({first: 'Nancy'});
  3606. * console.log(form.value); // {first: 'Nancy', last: null}
  3607. * ```
  3608. *
  3609. * @param value The object that matches the structure of the group.
  3610. * @param options Configuration options that determine how the control propagates changes and
  3611. * emits events after the value is patched.
  3612. * * `onlySelf`: When true, each change only affects this control and not its parent. Default is
  3613. * true.
  3614. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3615. * `valueChanges`
  3616. * observables emit events with the latest status and value when the control value is updated.
  3617. * When false, no events are emitted.
  3618. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  3619. * updateValueAndValidity} method.
  3620. */
  3621. FormGroup.prototype.patchValue = function (value, options) {
  3622. var _this = this;
  3623. if (options === void 0) { options = {}; }
  3624. Object.keys(value).forEach(function (name) {
  3625. if (_this.controls[name]) {
  3626. _this.controls[name].patchValue(value[name], { onlySelf: true, emitEvent: options.emitEvent });
  3627. }
  3628. });
  3629. this.updateValueAndValidity(options);
  3630. };
  3631. /**
  3632. * Resets the `FormGroup`, marks all descendants are marked `pristine` and `untouched`, and
  3633. * the value of all descendants to null.
  3634. *
  3635. * You reset to a specific form state by passing in a map of states
  3636. * that matches the structure of your form, with control names as keys. The state
  3637. * is a standalone value or a form state object with both a value and a disabled
  3638. * status.
  3639. *
  3640. * @param formState Resets the control with an initial value,
  3641. * or an object that defines the initial value and disabled state.
  3642. *
  3643. * @param options Configuration options that determine how the control propagates changes
  3644. * and emits events when the group is reset.
  3645. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
  3646. * false.
  3647. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3648. * `valueChanges`
  3649. * observables emit events with the latest status and value when the control is reset.
  3650. * When false, no events are emitted.
  3651. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  3652. * updateValueAndValidity} method.
  3653. *
  3654. * @usageNotes
  3655. *
  3656. * ### Reset the form group values
  3657. *
  3658. * ```ts
  3659. * const form = new FormGroup({
  3660. * first: new FormControl('first name'),
  3661. * last: new FormControl('last name')
  3662. * });
  3663. *
  3664. * console.log(form.value); // {first: 'first name', last: 'last name'}
  3665. *
  3666. * form.reset({ first: 'name', last: 'last name' });
  3667. *
  3668. * console.log(form.value); // {first: 'name', last: 'last name'}
  3669. * ```
  3670. *
  3671. * ### Reset the form group values and disabled status
  3672. *
  3673. * ```
  3674. * const form = new FormGroup({
  3675. * first: new FormControl('first name'),
  3676. * last: new FormControl('last name')
  3677. * });
  3678. *
  3679. * form.reset({
  3680. * first: {value: 'name', disabled: true},
  3681. * last: 'last'
  3682. * });
  3683. *
  3684. * console.log(this.form.value); // {first: 'name', last: 'last name'}
  3685. * console.log(this.form.get('first').status); // 'DISABLED'
  3686. * ```
  3687. */
  3688. FormGroup.prototype.reset = function (value, options) {
  3689. if (value === void 0) { value = {}; }
  3690. if (options === void 0) { options = {}; }
  3691. this._forEachChild(function (control, name) {
  3692. control.reset(value[name], { onlySelf: true, emitEvent: options.emitEvent });
  3693. });
  3694. this._updatePristine(options);
  3695. this._updateTouched(options);
  3696. this.updateValueAndValidity(options);
  3697. };
  3698. /**
  3699. * The aggregate value of the `FormGroup`, including any disabled controls.
  3700. *
  3701. * Retrieves all values regardless of disabled status.
  3702. * The `value` property is the best way to get the value of the group, because
  3703. * it excludes disabled controls in the `FormGroup`.
  3704. */
  3705. FormGroup.prototype.getRawValue = function () {
  3706. return this._reduceChildren({}, function (acc, control, name) {
  3707. acc[name] = control instanceof FormControl ? control.value : control.getRawValue();
  3708. return acc;
  3709. });
  3710. };
  3711. /** @internal */
  3712. FormGroup.prototype._syncPendingControls = function () {
  3713. var subtreeUpdated = this._reduceChildren(false, function (updated, child) {
  3714. return child._syncPendingControls() ? true : updated;
  3715. });
  3716. if (subtreeUpdated)
  3717. this.updateValueAndValidity({ onlySelf: true });
  3718. return subtreeUpdated;
  3719. };
  3720. /** @internal */
  3721. FormGroup.prototype._throwIfControlMissing = function (name) {
  3722. if (!Object.keys(this.controls).length) {
  3723. throw new Error("\n There are no form controls registered with this group yet. If you're using ngModel,\n you may want to check next tick (e.g. use setTimeout).\n ");
  3724. }
  3725. if (!this.controls[name]) {
  3726. throw new Error("Cannot find form control with name: " + name + ".");
  3727. }
  3728. };
  3729. /** @internal */
  3730. FormGroup.prototype._forEachChild = function (cb) {
  3731. var _this = this;
  3732. Object.keys(this.controls).forEach(function (k) { return cb(_this.controls[k], k); });
  3733. };
  3734. /** @internal */
  3735. FormGroup.prototype._setUpControls = function () {
  3736. var _this = this;
  3737. this._forEachChild(function (control) {
  3738. control.setParent(_this);
  3739. control._registerOnCollectionChange(_this._onCollectionChange);
  3740. });
  3741. };
  3742. /** @internal */
  3743. FormGroup.prototype._updateValue = function () { this.value = this._reduceValue(); };
  3744. /** @internal */
  3745. FormGroup.prototype._anyControls = function (condition) {
  3746. var _this = this;
  3747. var res = false;
  3748. this._forEachChild(function (control, name) {
  3749. res = res || (_this.contains(name) && condition(control));
  3750. });
  3751. return res;
  3752. };
  3753. /** @internal */
  3754. FormGroup.prototype._reduceValue = function () {
  3755. var _this = this;
  3756. return this._reduceChildren({}, function (acc, control, name) {
  3757. if (control.enabled || _this.disabled) {
  3758. acc[name] = control.value;
  3759. }
  3760. return acc;
  3761. });
  3762. };
  3763. /** @internal */
  3764. FormGroup.prototype._reduceChildren = function (initValue, fn) {
  3765. var res = initValue;
  3766. this._forEachChild(function (control, name) { res = fn(res, control, name); });
  3767. return res;
  3768. };
  3769. /** @internal */
  3770. FormGroup.prototype._allControlsDisabled = function () {
  3771. var e_1, _a;
  3772. try {
  3773. for (var _b = __values(Object.keys(this.controls)), _c = _b.next(); !_c.done; _c = _b.next()) {
  3774. var controlName = _c.value;
  3775. if (this.controls[controlName].enabled) {
  3776. return false;
  3777. }
  3778. }
  3779. }
  3780. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3781. finally {
  3782. try {
  3783. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  3784. }
  3785. finally { if (e_1) throw e_1.error; }
  3786. }
  3787. return Object.keys(this.controls).length > 0 || this.disabled;
  3788. };
  3789. /** @internal */
  3790. FormGroup.prototype._checkAllValuesPresent = function (value) {
  3791. this._forEachChild(function (control, name) {
  3792. if (value[name] === undefined) {
  3793. throw new Error("Must supply a value for form control with name: '" + name + "'.");
  3794. }
  3795. });
  3796. };
  3797. return FormGroup;
  3798. }(AbstractControl));
  3799. /**
  3800. * Tracks the value and validity state of an array of `FormControl`,
  3801. * `FormGroup` or `FormArray` instances.
  3802. *
  3803. * A `FormArray` aggregates the values of each child `FormControl` into an array.
  3804. * It calculates its status by reducing the status values of its children. For example, if one of
  3805. * the controls in a `FormArray` is invalid, the entire array becomes invalid.
  3806. *
  3807. * `FormArray` is one of the three fundamental building blocks used to define forms in Angular,
  3808. * along with `FormControl` and `FormGroup`.
  3809. *
  3810. * @usageNotes
  3811. *
  3812. * ### Create an array of form controls
  3813. *
  3814. * ```
  3815. * const arr = new FormArray([
  3816. * new FormControl('Nancy', Validators.minLength(2)),
  3817. * new FormControl('Drew'),
  3818. * ]);
  3819. *
  3820. * console.log(arr.value); // ['Nancy', 'Drew']
  3821. * console.log(arr.status); // 'VALID'
  3822. * ```
  3823. *
  3824. * ### Create a form array with array-level validators
  3825. *
  3826. * You include array-level validators and async validators. These come in handy
  3827. * when you want to perform validation that considers the value of more than one child
  3828. * control.
  3829. *
  3830. * The two types of validators are passed in separately as the second and third arg
  3831. * respectively, or together as part of an options object.
  3832. *
  3833. * ```
  3834. * const arr = new FormArray([
  3835. * new FormControl('Nancy'),
  3836. * new FormControl('Drew')
  3837. * ], {validators: myValidator, asyncValidators: myAsyncValidator});
  3838. * ```
  3839. *
  3840. * ### Set the updateOn property for all controls in a form array
  3841. *
  3842. * The options object is used to set a default value for each child
  3843. * control's `updateOn` property. If you set `updateOn` to `'blur'` at the
  3844. * array level, all child controls default to 'blur', unless the child
  3845. * has explicitly specified a different `updateOn` value.
  3846. *
  3847. * ```ts
  3848. * const arr = new FormArray([
  3849. * new FormControl()
  3850. * ], {updateOn: 'blur'});
  3851. * ```
  3852. *
  3853. * ### Adding or removing controls from a form array
  3854. *
  3855. * To change the controls in the array, use the `push`, `insert`, `removeAt` or `clear` methods
  3856. * in `FormArray` itself. These methods ensure the controls are properly tracked in the
  3857. * form's hierarchy. Do not modify the array of `AbstractControl`s used to instantiate
  3858. * the `FormArray` directly, as that result in strange and unexpected behavior such
  3859. * as broken change detection.
  3860. *
  3861. * @publicApi
  3862. */
  3863. var FormArray = /** @class */ (function (_super) {
  3864. __extends(FormArray, _super);
  3865. /**
  3866. * Creates a new `FormArray` instance.
  3867. *
  3868. * @param controls An array of child controls. Each child control is given an index
  3869. * where it is registered.
  3870. *
  3871. * @param validatorOrOpts A synchronous validator function, or an array of
  3872. * such functions, or an `AbstractControlOptions` object that contains validation functions
  3873. * and a validation trigger.
  3874. *
  3875. * @param asyncValidator A single async validator or array of async validator functions
  3876. *
  3877. */
  3878. function FormArray(controls, validatorOrOpts, asyncValidator) {
  3879. var _this = _super.call(this, coerceToValidator(validatorOrOpts), coerceToAsyncValidator(asyncValidator, validatorOrOpts)) || this;
  3880. _this.controls = controls;
  3881. _this._initObservables();
  3882. _this._setUpdateStrategy(validatorOrOpts);
  3883. _this._setUpControls();
  3884. _this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
  3885. return _this;
  3886. }
  3887. /**
  3888. * Get the `AbstractControl` at the given `index` in the array.
  3889. *
  3890. * @param index Index in the array to retrieve the control
  3891. */
  3892. FormArray.prototype.at = function (index) { return this.controls[index]; };
  3893. /**
  3894. * Insert a new `AbstractControl` at the end of the array.
  3895. *
  3896. * @param control Form control to be inserted
  3897. */
  3898. FormArray.prototype.push = function (control) {
  3899. this.controls.push(control);
  3900. this._registerControl(control);
  3901. this.updateValueAndValidity();
  3902. this._onCollectionChange();
  3903. };
  3904. /**
  3905. * Insert a new `AbstractControl` at the given `index` in the array.
  3906. *
  3907. * @param index Index in the array to insert the control
  3908. * @param control Form control to be inserted
  3909. */
  3910. FormArray.prototype.insert = function (index, control) {
  3911. this.controls.splice(index, 0, control);
  3912. this._registerControl(control);
  3913. this.updateValueAndValidity();
  3914. };
  3915. /**
  3916. * Remove the control at the given `index` in the array.
  3917. *
  3918. * @param index Index in the array to remove the control
  3919. */
  3920. FormArray.prototype.removeAt = function (index) {
  3921. if (this.controls[index])
  3922. this.controls[index]._registerOnCollectionChange(function () { });
  3923. this.controls.splice(index, 1);
  3924. this.updateValueAndValidity();
  3925. };
  3926. /**
  3927. * Replace an existing control.
  3928. *
  3929. * @param index Index in the array to replace the control
  3930. * @param control The `AbstractControl` control to replace the existing control
  3931. */
  3932. FormArray.prototype.setControl = function (index, control) {
  3933. if (this.controls[index])
  3934. this.controls[index]._registerOnCollectionChange(function () { });
  3935. this.controls.splice(index, 1);
  3936. if (control) {
  3937. this.controls.splice(index, 0, control);
  3938. this._registerControl(control);
  3939. }
  3940. this.updateValueAndValidity();
  3941. this._onCollectionChange();
  3942. };
  3943. Object.defineProperty(FormArray.prototype, "length", {
  3944. /**
  3945. * Length of the control array.
  3946. */
  3947. get: function () { return this.controls.length; },
  3948. enumerable: true,
  3949. configurable: true
  3950. });
  3951. /**
  3952. * Sets the value of the `FormArray`. It accepts an array that matches
  3953. * the structure of the control.
  3954. *
  3955. * This method performs strict checks, and throws an error if you try
  3956. * to set the value of a control that doesn't exist or if you exclude the
  3957. * value of a control.
  3958. *
  3959. * @usageNotes
  3960. * ### Set the values for the controls in the form array
  3961. *
  3962. * ```
  3963. * const arr = new FormArray([
  3964. * new FormControl(),
  3965. * new FormControl()
  3966. * ]);
  3967. * console.log(arr.value); // [null, null]
  3968. *
  3969. * arr.setValue(['Nancy', 'Drew']);
  3970. * console.log(arr.value); // ['Nancy', 'Drew']
  3971. * ```
  3972. *
  3973. * @param value Array of values for the controls
  3974. * @param options Configure options that determine how the control propagates changes and
  3975. * emits events after the value changes
  3976. *
  3977. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  3978. * is false.
  3979. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  3980. * `valueChanges`
  3981. * observables emit events with the latest status and value when the control value is updated.
  3982. * When false, no events are emitted.
  3983. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  3984. * updateValueAndValidity} method.
  3985. */
  3986. FormArray.prototype.setValue = function (value, options) {
  3987. var _this = this;
  3988. if (options === void 0) { options = {}; }
  3989. this._checkAllValuesPresent(value);
  3990. value.forEach(function (newValue, index) {
  3991. _this._throwIfControlMissing(index);
  3992. _this.at(index).setValue(newValue, { onlySelf: true, emitEvent: options.emitEvent });
  3993. });
  3994. this.updateValueAndValidity(options);
  3995. };
  3996. /**
  3997. * Patches the value of the `FormArray`. It accepts an array that matches the
  3998. * structure of the control, and does its best to match the values to the correct
  3999. * controls in the group.
  4000. *
  4001. * It accepts both super-sets and sub-sets of the array without throwing an error.
  4002. *
  4003. * @usageNotes
  4004. * ### Patch the values for controls in a form array
  4005. *
  4006. * ```
  4007. * const arr = new FormArray([
  4008. * new FormControl(),
  4009. * new FormControl()
  4010. * ]);
  4011. * console.log(arr.value); // [null, null]
  4012. *
  4013. * arr.patchValue(['Nancy']);
  4014. * console.log(arr.value); // ['Nancy', null]
  4015. * ```
  4016. *
  4017. * @param value Array of latest values for the controls
  4018. * @param options Configure options that determine how the control propagates changes and
  4019. * emits events after the value changes
  4020. *
  4021. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  4022. * is false.
  4023. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  4024. * `valueChanges`
  4025. * observables emit events with the latest status and value when the control value is updated.
  4026. * When false, no events are emitted.
  4027. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  4028. * updateValueAndValidity} method.
  4029. */
  4030. FormArray.prototype.patchValue = function (value, options) {
  4031. var _this = this;
  4032. if (options === void 0) { options = {}; }
  4033. value.forEach(function (newValue, index) {
  4034. if (_this.at(index)) {
  4035. _this.at(index).patchValue(newValue, { onlySelf: true, emitEvent: options.emitEvent });
  4036. }
  4037. });
  4038. this.updateValueAndValidity(options);
  4039. };
  4040. /**
  4041. * Resets the `FormArray` and all descendants are marked `pristine` and `untouched`, and the
  4042. * value of all descendants to null or null maps.
  4043. *
  4044. * You reset to a specific form state by passing in an array of states
  4045. * that matches the structure of the control. The state is a standalone value
  4046. * or a form state object with both a value and a disabled status.
  4047. *
  4048. * @usageNotes
  4049. * ### Reset the values in a form array
  4050. *
  4051. * ```ts
  4052. * const arr = new FormArray([
  4053. * new FormControl(),
  4054. * new FormControl()
  4055. * ]);
  4056. * arr.reset(['name', 'last name']);
  4057. *
  4058. * console.log(this.arr.value); // ['name', 'last name']
  4059. * ```
  4060. *
  4061. * ### Reset the values in a form array and the disabled status for the first control
  4062. *
  4063. * ```
  4064. * this.arr.reset([
  4065. * {value: 'name', disabled: true},
  4066. * 'last'
  4067. * ]);
  4068. *
  4069. * console.log(this.arr.value); // ['name', 'last name']
  4070. * console.log(this.arr.get(0).status); // 'DISABLED'
  4071. * ```
  4072. *
  4073. * @param value Array of values for the controls
  4074. * @param options Configure options that determine how the control propagates changes and
  4075. * emits events after the value changes
  4076. *
  4077. * * `onlySelf`: When true, each change only affects this control, and not its parent. Default
  4078. * is false.
  4079. * * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
  4080. * `valueChanges`
  4081. * observables emit events with the latest status and value when the control is reset.
  4082. * When false, no events are emitted.
  4083. * The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
  4084. * updateValueAndValidity} method.
  4085. */
  4086. FormArray.prototype.reset = function (value, options) {
  4087. if (value === void 0) { value = []; }
  4088. if (options === void 0) { options = {}; }
  4089. this._forEachChild(function (control, index) {
  4090. control.reset(value[index], { onlySelf: true, emitEvent: options.emitEvent });
  4091. });
  4092. this._updatePristine(options);
  4093. this._updateTouched(options);
  4094. this.updateValueAndValidity(options);
  4095. };
  4096. /**
  4097. * The aggregate value of the array, including any disabled controls.
  4098. *
  4099. * Reports all values regardless of disabled status.
  4100. * For enabled controls only, the `value` property is the best way to get the value of the array.
  4101. */
  4102. FormArray.prototype.getRawValue = function () {
  4103. return this.controls.map(function (control) {
  4104. return control instanceof FormControl ? control.value : control.getRawValue();
  4105. });
  4106. };
  4107. /**
  4108. * Remove all controls in the `FormArray`.
  4109. *
  4110. * @usageNotes
  4111. * ### Remove all elements from a FormArray
  4112. *
  4113. * ```ts
  4114. * const arr = new FormArray([
  4115. * new FormControl(),
  4116. * new FormControl()
  4117. * ]);
  4118. * console.log(arr.length); // 2
  4119. *
  4120. * arr.clear();
  4121. * console.log(arr.length); // 0
  4122. * ```
  4123. *
  4124. * It's a simpler and more efficient alternative to removing all elements one by one:
  4125. *
  4126. * ```ts
  4127. * const arr = new FormArray([
  4128. * new FormControl(),
  4129. * new FormControl()
  4130. * ]);
  4131. *
  4132. * while (arr.length) {
  4133. * arr.removeAt(0);
  4134. * }
  4135. * ```
  4136. */
  4137. FormArray.prototype.clear = function () {
  4138. if (this.controls.length < 1)
  4139. return;
  4140. this._forEachChild(function (control) { return control._registerOnCollectionChange(function () { }); });
  4141. this.controls.splice(0);
  4142. this.updateValueAndValidity();
  4143. };
  4144. /** @internal */
  4145. FormArray.prototype._syncPendingControls = function () {
  4146. var subtreeUpdated = this.controls.reduce(function (updated, child) {
  4147. return child._syncPendingControls() ? true : updated;
  4148. }, false);
  4149. if (subtreeUpdated)
  4150. this.updateValueAndValidity({ onlySelf: true });
  4151. return subtreeUpdated;
  4152. };
  4153. /** @internal */
  4154. FormArray.prototype._throwIfControlMissing = function (index) {
  4155. if (!this.controls.length) {
  4156. throw new Error("\n There are no form controls registered with this array yet. If you're using ngModel,\n you may want to check next tick (e.g. use setTimeout).\n ");
  4157. }
  4158. if (!this.at(index)) {
  4159. throw new Error("Cannot find form control at index " + index);
  4160. }
  4161. };
  4162. /** @internal */
  4163. FormArray.prototype._forEachChild = function (cb) {
  4164. this.controls.forEach(function (control, index) { cb(control, index); });
  4165. };
  4166. /** @internal */
  4167. FormArray.prototype._updateValue = function () {
  4168. var _this = this;
  4169. this.value =
  4170. this.controls.filter(function (control) { return control.enabled || _this.disabled; })
  4171. .map(function (control) { return control.value; });
  4172. };
  4173. /** @internal */
  4174. FormArray.prototype._anyControls = function (condition) {
  4175. return this.controls.some(function (control) { return control.enabled && condition(control); });
  4176. };
  4177. /** @internal */
  4178. FormArray.prototype._setUpControls = function () {
  4179. var _this = this;
  4180. this._forEachChild(function (control) { return _this._registerControl(control); });
  4181. };
  4182. /** @internal */
  4183. FormArray.prototype._checkAllValuesPresent = function (value) {
  4184. this._forEachChild(function (control, i) {
  4185. if (value[i] === undefined) {
  4186. throw new Error("Must supply a value for form control at index: " + i + ".");
  4187. }
  4188. });
  4189. };
  4190. /** @internal */
  4191. FormArray.prototype._allControlsDisabled = function () {
  4192. var e_2, _a;
  4193. try {
  4194. for (var _b = __values(this.controls), _c = _b.next(); !_c.done; _c = _b.next()) {
  4195. var control = _c.value;
  4196. if (control.enabled)
  4197. return false;
  4198. }
  4199. }
  4200. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  4201. finally {
  4202. try {
  4203. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  4204. }
  4205. finally { if (e_2) throw e_2.error; }
  4206. }
  4207. return this.controls.length > 0 || this.disabled;
  4208. };
  4209. FormArray.prototype._registerControl = function (control) {
  4210. control.setParent(this);
  4211. control._registerOnCollectionChange(this._onCollectionChange);
  4212. };
  4213. return FormArray;
  4214. }(AbstractControl));
  4215. /**
  4216. * @license
  4217. * Copyright Google Inc. All Rights Reserved.
  4218. *
  4219. * Use of this source code is governed by an MIT-style license that can be
  4220. * found in the LICENSE file at https://angular.io/license
  4221. */
  4222. var formDirectiveProvider = {
  4223. provide: ControlContainer,
  4224. useExisting: core.forwardRef(function () { return NgForm; })
  4225. };
  4226. var ɵ0 = function () { return Promise.resolve(null); };
  4227. var resolvedPromise = (ɵ0)();
  4228. /**
  4229. * @description
  4230. * Creates a top-level `FormGroup` instance and binds it to a form
  4231. * to track aggregate form value and validation status.
  4232. *
  4233. * As soon as you import the `FormsModule`, this directive becomes active by default on
  4234. * all `<form>` tags. You don't need to add a special selector.
  4235. *
  4236. * You optionally export the directive into a local template variable using `ngForm` as the key
  4237. * (ex: `#myForm="ngForm"`). This is optional, but useful. Many properties from the underlying
  4238. * `FormGroup` instance are duplicated on the directive itself, so a reference to it
  4239. * gives you access to the aggregate value and validity status of the form, as well as
  4240. * user interaction properties like `dirty` and `touched`.
  4241. *
  4242. * To register child controls with the form, use `NgModel` with a `name`
  4243. * attribute. You may use `NgModelGroup` to create sub-groups within the form.
  4244. *
  4245. * If necessary, listen to the directive's `ngSubmit` event to be notified when the user has
  4246. * triggered a form submission. The `ngSubmit` event emits the original form
  4247. * submission event.
  4248. *
  4249. * In template driven forms, all `<form>` tags are automatically tagged as `NgForm`.
  4250. * To import the `FormsModule` but skip its usage in some forms,
  4251. * for example, to use native HTML5 validation, add the `ngNoForm` and the `<form>`
  4252. * tags won't create an `NgForm` directive. In reactive forms, using `ngNoForm` is
  4253. * unnecessary because the `<form>` tags are inert. In that case, you would
  4254. * refrain from using the `formGroup` directive.
  4255. *
  4256. * @usageNotes
  4257. *
  4258. * ### Migrating from deprecated ngForm selector
  4259. *
  4260. * Support for using `ngForm` element selector has been deprecated in Angular v6 and will be removed
  4261. * in Angular v9.
  4262. *
  4263. * This has been deprecated to keep selectors consistent with other core Angular selectors,
  4264. * as element selectors are typically written in kebab-case.
  4265. *
  4266. * Now deprecated:
  4267. * ```html
  4268. * <ngForm #myForm="ngForm">
  4269. * ```
  4270. *
  4271. * After:
  4272. * ```html
  4273. * <ng-form #myForm="ngForm">
  4274. * ```
  4275. *
  4276. * ### Listening for form submission
  4277. *
  4278. * The following example shows how to capture the form values from the "ngSubmit" event.
  4279. *
  4280. * {@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
  4281. *
  4282. * ### Setting the update options
  4283. *
  4284. * The following example shows you how to change the "updateOn" option from its default using
  4285. * ngFormOptions.
  4286. *
  4287. * ```html
  4288. * <form [ngFormOptions]="{updateOn: 'blur'}">
  4289. * <input name="one" ngModel> <!-- this ngModel will update on blur -->
  4290. * </form>
  4291. * ```
  4292. *
  4293. * @ngModule FormsModule
  4294. * @publicApi
  4295. */
  4296. var NgForm = /** @class */ (function (_super) {
  4297. __extends(NgForm, _super);
  4298. function NgForm(validators, asyncValidators) {
  4299. var _this = _super.call(this) || this;
  4300. /**
  4301. * @description
  4302. * Returns whether the form submission has been triggered.
  4303. */
  4304. _this.submitted = false;
  4305. _this._directives = [];
  4306. /**
  4307. * @description
  4308. * Event emitter for the "ngSubmit" event
  4309. */
  4310. _this.ngSubmit = new core.EventEmitter();
  4311. _this.form =
  4312. new FormGroup({}, composeValidators(validators), composeAsyncValidators(asyncValidators));
  4313. return _this;
  4314. }
  4315. /**
  4316. * @description
  4317. * Lifecycle method called after the view is initialized. For internal use only.
  4318. */
  4319. NgForm.prototype.ngAfterViewInit = function () { this._setUpdateStrategy(); };
  4320. Object.defineProperty(NgForm.prototype, "formDirective", {
  4321. /**
  4322. * @description
  4323. * The directive instance.
  4324. */
  4325. get: function () { return this; },
  4326. enumerable: true,
  4327. configurable: true
  4328. });
  4329. Object.defineProperty(NgForm.prototype, "control", {
  4330. /**
  4331. * @description
  4332. * The internal `FormGroup` instance.
  4333. */
  4334. get: function () { return this.form; },
  4335. enumerable: true,
  4336. configurable: true
  4337. });
  4338. Object.defineProperty(NgForm.prototype, "path", {
  4339. /**
  4340. * @description
  4341. * Returns an array representing the path to this group. Because this directive
  4342. * always lives at the top level of a form, it is always an empty array.
  4343. */
  4344. get: function () { return []; },
  4345. enumerable: true,
  4346. configurable: true
  4347. });
  4348. Object.defineProperty(NgForm.prototype, "controls", {
  4349. /**
  4350. * @description
  4351. * Returns a map of the controls in this group.
  4352. */
  4353. get: function () { return this.form.controls; },
  4354. enumerable: true,
  4355. configurable: true
  4356. });
  4357. /**
  4358. * @description
  4359. * Method that sets up the control directive in this group, re-calculates its value
  4360. * and validity, and adds the instance to the internal list of directives.
  4361. *
  4362. * @param dir The `NgModel` directive instance.
  4363. */
  4364. NgForm.prototype.addControl = function (dir) {
  4365. var _this = this;
  4366. resolvedPromise.then(function () {
  4367. var container = _this._findContainer(dir.path);
  4368. dir.control =
  4369. container.registerControl(dir.name, dir.control);
  4370. setUpControl(dir.control, dir);
  4371. dir.control.updateValueAndValidity({ emitEvent: false });
  4372. _this._directives.push(dir);
  4373. });
  4374. };
  4375. /**
  4376. * @description
  4377. * Retrieves the `FormControl` instance from the provided `NgModel` directive.
  4378. *
  4379. * @param dir The `NgModel` directive instance.
  4380. */
  4381. NgForm.prototype.getControl = function (dir) { return this.form.get(dir.path); };
  4382. /**
  4383. * @description
  4384. * Removes the `NgModel` instance from the internal list of directives
  4385. *
  4386. * @param dir The `NgModel` directive instance.
  4387. */
  4388. NgForm.prototype.removeControl = function (dir) {
  4389. var _this = this;
  4390. resolvedPromise.then(function () {
  4391. var container = _this._findContainer(dir.path);
  4392. if (container) {
  4393. container.removeControl(dir.name);
  4394. }
  4395. removeDir(_this._directives, dir);
  4396. });
  4397. };
  4398. /**
  4399. * @description
  4400. * Adds a new `NgModelGroup` directive instance to the form.
  4401. *
  4402. * @param dir The `NgModelGroup` directive instance.
  4403. */
  4404. NgForm.prototype.addFormGroup = function (dir) {
  4405. var _this = this;
  4406. resolvedPromise.then(function () {
  4407. var container = _this._findContainer(dir.path);
  4408. var group = new FormGroup({});
  4409. setUpFormContainer(group, dir);
  4410. container.registerControl(dir.name, group);
  4411. group.updateValueAndValidity({ emitEvent: false });
  4412. });
  4413. };
  4414. /**
  4415. * @description
  4416. * Removes the `NgModelGroup` directive instance from the form.
  4417. *
  4418. * @param dir The `NgModelGroup` directive instance.
  4419. */
  4420. NgForm.prototype.removeFormGroup = function (dir) {
  4421. var _this = this;
  4422. resolvedPromise.then(function () {
  4423. var container = _this._findContainer(dir.path);
  4424. if (container) {
  4425. container.removeControl(dir.name);
  4426. }
  4427. });
  4428. };
  4429. /**
  4430. * @description
  4431. * Retrieves the `FormGroup` for a provided `NgModelGroup` directive instance
  4432. *
  4433. * @param dir The `NgModelGroup` directive instance.
  4434. */
  4435. NgForm.prototype.getFormGroup = function (dir) { return this.form.get(dir.path); };
  4436. /**
  4437. * Sets the new value for the provided `NgControl` directive.
  4438. *
  4439. * @param dir The `NgControl` directive instance.
  4440. * @param value The new value for the directive's control.
  4441. */
  4442. NgForm.prototype.updateModel = function (dir, value) {
  4443. var _this = this;
  4444. resolvedPromise.then(function () {
  4445. var ctrl = _this.form.get(dir.path);
  4446. ctrl.setValue(value);
  4447. });
  4448. };
  4449. /**
  4450. * @description
  4451. * Sets the value for this `FormGroup`.
  4452. *
  4453. * @param value The new value
  4454. */
  4455. NgForm.prototype.setValue = function (value) { this.control.setValue(value); };
  4456. /**
  4457. * @description
  4458. * Method called when the "submit" event is triggered on the form.
  4459. * Triggers the `ngSubmit` emitter to emit the "submit" event as its payload.
  4460. *
  4461. * @param $event The "submit" event object
  4462. */
  4463. NgForm.prototype.onSubmit = function ($event) {
  4464. this.submitted = true;
  4465. syncPendingControls(this.form, this._directives);
  4466. this.ngSubmit.emit($event);
  4467. return false;
  4468. };
  4469. /**
  4470. * @description
  4471. * Method called when the "reset" event is triggered on the form.
  4472. */
  4473. NgForm.prototype.onReset = function () { this.resetForm(); };
  4474. /**
  4475. * @description
  4476. * Resets the form to an initial value and resets its submitted status.
  4477. *
  4478. * @param value The new value for the form.
  4479. */
  4480. NgForm.prototype.resetForm = function (value) {
  4481. if (value === void 0) { value = undefined; }
  4482. this.form.reset(value);
  4483. this.submitted = false;
  4484. };
  4485. NgForm.prototype._setUpdateStrategy = function () {
  4486. if (this.options && this.options.updateOn != null) {
  4487. this.form._updateOn = this.options.updateOn;
  4488. }
  4489. };
  4490. /** @internal */
  4491. NgForm.prototype._findContainer = function (path) {
  4492. path.pop();
  4493. return path.length ? this.form.get(path) : this.form;
  4494. };
  4495. __decorate([
  4496. core.Input('ngFormOptions'),
  4497. __metadata("design:type", Object)
  4498. ], NgForm.prototype, "options", void 0);
  4499. NgForm = __decorate([
  4500. core.Directive({
  4501. selector: 'form:not([ngNoForm]):not([formGroup]),ngForm,ng-form,[ngForm]',
  4502. providers: [formDirectiveProvider],
  4503. host: { '(submit)': 'onSubmit($event)', '(reset)': 'onReset()' },
  4504. outputs: ['ngSubmit'],
  4505. exportAs: 'ngForm'
  4506. }),
  4507. __param(0, core.Optional()), __param(0, core.Self()), __param(0, core.Inject(NG_VALIDATORS)),
  4508. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_ASYNC_VALIDATORS)),
  4509. __metadata("design:paramtypes", [Array, Array])
  4510. ], NgForm);
  4511. return NgForm;
  4512. }(ControlContainer));
  4513. /**
  4514. * @license
  4515. * Copyright Google Inc. All Rights Reserved.
  4516. *
  4517. * Use of this source code is governed by an MIT-style license that can be
  4518. * found in the LICENSE file at https://angular.io/license
  4519. */
  4520. var TemplateDrivenErrors = /** @class */ (function () {
  4521. function TemplateDrivenErrors() {
  4522. }
  4523. TemplateDrivenErrors.modelParentException = function () {
  4524. throw new Error("\n ngModel cannot be used to register form controls with a parent formGroup directive. Try using\n formGroup's partner directive \"formControlName\" instead. Example:\n\n " + FormErrorExamples.formControlName + "\n\n Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:\n\n Example:\n\n " + FormErrorExamples.ngModelWithFormGroup);
  4525. };
  4526. TemplateDrivenErrors.formGroupNameException = function () {
  4527. throw new Error("\n ngModel cannot be used to register form controls with a parent formGroupName or formArrayName directive.\n\n Option 1: Use formControlName instead of ngModel (reactive strategy):\n\n " + FormErrorExamples.formGroupName + "\n\n Option 2: Update ngModel's parent be ngModelGroup (template-driven strategy):\n\n " + FormErrorExamples.ngModelGroup);
  4528. };
  4529. TemplateDrivenErrors.missingNameException = function () {
  4530. throw new Error("If ngModel is used within a form tag, either the name attribute must be set or the form\n control must be defined as 'standalone' in ngModelOptions.\n\n Example 1: <input [(ngModel)]=\"person.firstName\" name=\"first\">\n Example 2: <input [(ngModel)]=\"person.firstName\" [ngModelOptions]=\"{standalone: true}\">");
  4531. };
  4532. TemplateDrivenErrors.modelGroupParentException = function () {
  4533. throw new Error("\n ngModelGroup cannot be used with a parent formGroup directive.\n\n Option 1: Use formGroupName instead of ngModelGroup (reactive strategy):\n\n " + FormErrorExamples.formGroupName + "\n\n Option 2: Use a regular form tag instead of the formGroup directive (template-driven strategy):\n\n " + FormErrorExamples.ngModelGroup);
  4534. };
  4535. TemplateDrivenErrors.ngFormWarning = function () {
  4536. console.warn("\n It looks like you're using 'ngForm'.\n\n Support for using the 'ngForm' element selector has been deprecated in Angular v6 and will be removed\n in Angular v9.\n\n Use 'ng-form' instead.\n\n Before:\n <ngForm #myForm=\"ngForm\">\n\n After:\n <ng-form #myForm=\"ngForm\">\n ");
  4537. };
  4538. return TemplateDrivenErrors;
  4539. }());
  4540. /**
  4541. * @license
  4542. * Copyright Google Inc. All Rights Reserved.
  4543. *
  4544. * Use of this source code is governed by an MIT-style license that can be
  4545. * found in the LICENSE file at https://angular.io/license
  4546. */
  4547. /**
  4548. * @description
  4549. * `InjectionToken` to provide to turn off the warning when using 'ngForm' deprecated selector.
  4550. */
  4551. var NG_FORM_SELECTOR_WARNING = new core.InjectionToken('NgFormSelectorWarning');
  4552. /**
  4553. * This directive is solely used to display warnings when the deprecated `ngForm` selector is used.
  4554. *
  4555. * @deprecated in Angular v6 and will be removed in Angular v9.
  4556. * @ngModule FormsModule
  4557. * @publicApi
  4558. */
  4559. var NgFormSelectorWarning = /** @class */ (function () {
  4560. function NgFormSelectorWarning(ngFormWarning) {
  4561. if (((!ngFormWarning || ngFormWarning === 'once') && !NgFormSelectorWarning_1._ngFormWarning) ||
  4562. ngFormWarning === 'always') {
  4563. TemplateDrivenErrors.ngFormWarning();
  4564. NgFormSelectorWarning_1._ngFormWarning = true;
  4565. }
  4566. }
  4567. NgFormSelectorWarning_1 = NgFormSelectorWarning;
  4568. var NgFormSelectorWarning_1;
  4569. /**
  4570. * Static property used to track whether the deprecation warning for this selector has been sent.
  4571. * Used to support warning config of "once".
  4572. *
  4573. * @internal
  4574. */
  4575. NgFormSelectorWarning._ngFormWarning = false;
  4576. NgFormSelectorWarning = NgFormSelectorWarning_1 = __decorate([
  4577. core.Directive({ selector: 'ngForm' }),
  4578. __param(0, core.Optional()), __param(0, core.Inject(NG_FORM_SELECTOR_WARNING)),
  4579. __metadata("design:paramtypes", [Object])
  4580. ], NgFormSelectorWarning);
  4581. return NgFormSelectorWarning;
  4582. }());
  4583. /**
  4584. * @license
  4585. * Copyright Google Inc. All Rights Reserved.
  4586. *
  4587. * Use of this source code is governed by an MIT-style license that can be
  4588. * found in the LICENSE file at https://angular.io/license
  4589. */
  4590. /**
  4591. * @description
  4592. * A base class for code shared between the `NgModelGroup` and `FormGroupName` directives.
  4593. *
  4594. * @publicApi
  4595. */
  4596. var AbstractFormGroupDirective = /** @class */ (function (_super) {
  4597. __extends(AbstractFormGroupDirective, _super);
  4598. function AbstractFormGroupDirective() {
  4599. return _super !== null && _super.apply(this, arguments) || this;
  4600. }
  4601. /**
  4602. * @description
  4603. * An internal callback method triggered on the instance after the inputs are set.
  4604. * Registers the group with its parent group.
  4605. */
  4606. AbstractFormGroupDirective.prototype.ngOnInit = function () {
  4607. this._checkParentType();
  4608. this.formDirective.addFormGroup(this);
  4609. };
  4610. /**
  4611. * @description
  4612. * An internal callback method triggered before the instance is destroyed.
  4613. * Removes the group from its parent group.
  4614. */
  4615. AbstractFormGroupDirective.prototype.ngOnDestroy = function () {
  4616. if (this.formDirective) {
  4617. this.formDirective.removeFormGroup(this);
  4618. }
  4619. };
  4620. Object.defineProperty(AbstractFormGroupDirective.prototype, "control", {
  4621. /**
  4622. * @description
  4623. * The `FormGroup` bound to this directive.
  4624. */
  4625. get: function () { return this.formDirective.getFormGroup(this); },
  4626. enumerable: true,
  4627. configurable: true
  4628. });
  4629. Object.defineProperty(AbstractFormGroupDirective.prototype, "path", {
  4630. /**
  4631. * @description
  4632. * The path to this group from the top-level directive.
  4633. */
  4634. get: function () { return controlPath(this.name, this._parent); },
  4635. enumerable: true,
  4636. configurable: true
  4637. });
  4638. Object.defineProperty(AbstractFormGroupDirective.prototype, "formDirective", {
  4639. /**
  4640. * @description
  4641. * The top-level directive for this group if present, otherwise null.
  4642. */
  4643. get: function () { return this._parent ? this._parent.formDirective : null; },
  4644. enumerable: true,
  4645. configurable: true
  4646. });
  4647. Object.defineProperty(AbstractFormGroupDirective.prototype, "validator", {
  4648. /**
  4649. * @description
  4650. * The synchronous validators registered with this group.
  4651. */
  4652. get: function () { return composeValidators(this._validators); },
  4653. enumerable: true,
  4654. configurable: true
  4655. });
  4656. Object.defineProperty(AbstractFormGroupDirective.prototype, "asyncValidator", {
  4657. /**
  4658. * @description
  4659. * The async validators registered with this group.
  4660. */
  4661. get: function () {
  4662. return composeAsyncValidators(this._asyncValidators);
  4663. },
  4664. enumerable: true,
  4665. configurable: true
  4666. });
  4667. /** @internal */
  4668. AbstractFormGroupDirective.prototype._checkParentType = function () { };
  4669. return AbstractFormGroupDirective;
  4670. }(ControlContainer));
  4671. /**
  4672. * @license
  4673. * Copyright Google Inc. All Rights Reserved.
  4674. *
  4675. * Use of this source code is governed by an MIT-style license that can be
  4676. * found in the LICENSE file at https://angular.io/license
  4677. */
  4678. var modelGroupProvider = {
  4679. provide: ControlContainer,
  4680. useExisting: core.forwardRef(function () { return NgModelGroup; })
  4681. };
  4682. /**
  4683. * @description
  4684. * Creates and binds a `FormGroup` instance to a DOM element.
  4685. *
  4686. * This directive can only be used as a child of `NgForm` (within `<form>` tags).
  4687. *
  4688. * Use this directive to validate a sub-group of your form separately from the
  4689. * rest of your form, or if some values in your domain model make more sense
  4690. * to consume together in a nested object.
  4691. *
  4692. * Provide a name for the sub-group and it will become the key
  4693. * for the sub-group in the form's full value. If you need direct access, export the directive into
  4694. * a local template variable using `ngModelGroup` (ex: `#myGroup="ngModelGroup"`).
  4695. *
  4696. * @usageNotes
  4697. *
  4698. * ### Consuming controls in a grouping
  4699. *
  4700. * The following example shows you how to combine controls together in a sub-group
  4701. * of the form.
  4702. *
  4703. * {@example forms/ts/ngModelGroup/ng_model_group_example.ts region='Component'}
  4704. *
  4705. * @ngModule FormsModule
  4706. * @publicApi
  4707. */
  4708. var NgModelGroup = /** @class */ (function (_super) {
  4709. __extends(NgModelGroup, _super);
  4710. function NgModelGroup(parent, validators, asyncValidators) {
  4711. var _this = _super.call(this) || this;
  4712. _this._parent = parent;
  4713. _this._validators = validators;
  4714. _this._asyncValidators = asyncValidators;
  4715. return _this;
  4716. }
  4717. NgModelGroup_1 = NgModelGroup;
  4718. /** @internal */
  4719. NgModelGroup.prototype._checkParentType = function () {
  4720. if (!(this._parent instanceof NgModelGroup_1) && !(this._parent instanceof NgForm)) {
  4721. TemplateDrivenErrors.modelGroupParentException();
  4722. }
  4723. };
  4724. var NgModelGroup_1;
  4725. __decorate([
  4726. core.Input('ngModelGroup'),
  4727. __metadata("design:type", String)
  4728. ], NgModelGroup.prototype, "name", void 0);
  4729. NgModelGroup = NgModelGroup_1 = __decorate([
  4730. core.Directive({ selector: '[ngModelGroup]', providers: [modelGroupProvider], exportAs: 'ngModelGroup' }),
  4731. __param(0, core.Host()), __param(0, core.SkipSelf()),
  4732. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_VALIDATORS)),
  4733. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_ASYNC_VALIDATORS)),
  4734. __metadata("design:paramtypes", [ControlContainer, Array, Array])
  4735. ], NgModelGroup);
  4736. return NgModelGroup;
  4737. }(AbstractFormGroupDirective));
  4738. /**
  4739. * @license
  4740. * Copyright Google Inc. All Rights Reserved.
  4741. *
  4742. * Use of this source code is governed by an MIT-style license that can be
  4743. * found in the LICENSE file at https://angular.io/license
  4744. */
  4745. var formControlBinding = {
  4746. provide: NgControl,
  4747. useExisting: core.forwardRef(function () { return NgModel; })
  4748. };
  4749. var ɵ0$1 = function () { return Promise.resolve(null); };
  4750. /**
  4751. * `ngModel` forces an additional change detection run when its inputs change:
  4752. * E.g.:
  4753. * ```
  4754. * <div>{{myModel.valid}}</div>
  4755. * <input [(ngModel)]="myValue" #myModel="ngModel">
  4756. * ```
  4757. * I.e. `ngModel` can export itself on the element and then be used in the template.
  4758. * Normally, this would result in expressions before the `input` that use the exported directive
  4759. * to have and old value as they have been
  4760. * dirty checked before. As this is a very common case for `ngModel`, we added this second change
  4761. * detection run.
  4762. *
  4763. * Notes:
  4764. * - this is just one extra run no matter how many `ngModel` have been changed.
  4765. * - this is a general problem when using `exportAs` for directives!
  4766. */
  4767. var resolvedPromise$1 = (ɵ0$1)();
  4768. /**
  4769. * @description
  4770. * Creates a `FormControl` instance from a domain model and binds it
  4771. * to a form control element.
  4772. *
  4773. * The `FormControl` instance tracks the value, user interaction, and
  4774. * validation status of the control and keeps the view synced with the model. If used
  4775. * within a parent form, the directive also registers itself with the form as a child
  4776. * control.
  4777. *
  4778. * This directive is used by itself or as part of a larger form. Use the
  4779. * `ngModel` selector to activate it.
  4780. *
  4781. * It accepts a domain model as an optional `Input`. If you have a one-way binding
  4782. * to `ngModel` with `[]` syntax, changing the value of the domain model in the component
  4783. * class sets the value in the view. If you have a two-way binding with `[()]` syntax
  4784. * (also known as 'banana-box syntax'), the value in the UI always syncs back to
  4785. * the domain model in your class.
  4786. *
  4787. * To inspect the properties of the associated `FormControl` (like validity state),
  4788. * export the directive into a local template variable using `ngModel` as the key (ex: `#myVar="ngModel"`).
  4789. * You then access the control using the directive's `control` property,
  4790. * but most properties used (like `valid` and `dirty`) fall through to the control anyway for direct access.
  4791. * See a full list of properties directly available in `AbstractControlDirective`.
  4792. *
  4793. * @see `RadioControlValueAccessor`
  4794. * @see `SelectControlValueAccessor`
  4795. *
  4796. * @usageNotes
  4797. *
  4798. * ### Using ngModel on a standalone control
  4799. *
  4800. * The following examples show a simple standalone control using `ngModel`:
  4801. *
  4802. * {@example forms/ts/simpleNgModel/simple_ng_model_example.ts region='Component'}
  4803. *
  4804. * When using the `ngModel` within `<form>` tags, you'll also need to supply a `name` attribute
  4805. * so that the control can be registered with the parent form under that name.
  4806. *
  4807. * In the context of a parent form, it's often unnecessary to include one-way or two-way binding,
  4808. * as the parent form syncs the value for you. You access its properties by exporting it into a
  4809. * local template variable using `ngForm` such as (`#f="ngForm"`). Use the variable where
  4810. * needed on form submission.
  4811. *
  4812. * If you do need to populate initial values into your form, using a one-way binding for
  4813. * `ngModel` tends to be sufficient as long as you use the exported form's value rather
  4814. * than the domain model's value on submit.
  4815. *
  4816. * ### Using ngModel within a form
  4817. *
  4818. * The following example shows controls using `ngModel` within a form:
  4819. *
  4820. * {@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
  4821. *
  4822. * ### Using a standalone ngModel within a group
  4823. *
  4824. * The following example shows you how to use a standalone ngModel control
  4825. * within a form. This controls the display of the form, but doesn't contain form data.
  4826. *
  4827. * ```html
  4828. * <form>
  4829. * <input name="login" ngModel placeholder="Login">
  4830. * <input type="checkbox" ngModel [ngModelOptions]="{standalone: true}"> Show more options?
  4831. * </form>
  4832. * <!-- form value: {login: ''} -->
  4833. * ```
  4834. *
  4835. * ### Setting the ngModel name attribute through options
  4836. *
  4837. * The following example shows you an alternate way to set the name attribute. The name attribute is used
  4838. * within a custom form component, and the name `@Input` property serves a different purpose.
  4839. *
  4840. * ```html
  4841. * <form>
  4842. * <my-person-control name="Nancy" ngModel [ngModelOptions]="{name: 'user'}">
  4843. * </my-person-control>
  4844. * </form>
  4845. * <!-- form value: {user: ''} -->
  4846. * ```
  4847. *
  4848. * @ngModule FormsModule
  4849. * @publicApi
  4850. */
  4851. var NgModel = /** @class */ (function (_super) {
  4852. __extends(NgModel, _super);
  4853. function NgModel(parent, validators, asyncValidators, valueAccessors) {
  4854. var _this = _super.call(this) || this;
  4855. _this.control = new FormControl();
  4856. /** @internal */
  4857. _this._registered = false;
  4858. /**
  4859. * @description
  4860. * Event emitter for producing the `ngModelChange` event after
  4861. * the view model updates.
  4862. */
  4863. _this.update = new core.EventEmitter();
  4864. _this._parent = parent;
  4865. _this._rawValidators = validators || [];
  4866. _this._rawAsyncValidators = asyncValidators || [];
  4867. _this.valueAccessor = selectValueAccessor(_this, valueAccessors);
  4868. return _this;
  4869. }
  4870. /**
  4871. * @description
  4872. * A lifecycle method called when the directive's inputs change. For internal use
  4873. * only.
  4874. *
  4875. * @param changes A object of key/value pairs for the set of changed inputs.
  4876. */
  4877. NgModel.prototype.ngOnChanges = function (changes) {
  4878. this._checkForErrors();
  4879. if (!this._registered)
  4880. this._setUpControl();
  4881. if ('isDisabled' in changes) {
  4882. this._updateDisabled(changes);
  4883. }
  4884. if (isPropertyUpdated(changes, this.viewModel)) {
  4885. this._updateValue(this.model);
  4886. this.viewModel = this.model;
  4887. }
  4888. };
  4889. /**
  4890. * @description
  4891. * Lifecycle method called before the directive's instance is destroyed. For internal
  4892. * use only.
  4893. */
  4894. NgModel.prototype.ngOnDestroy = function () { this.formDirective && this.formDirective.removeControl(this); };
  4895. Object.defineProperty(NgModel.prototype, "path", {
  4896. /**
  4897. * @description
  4898. * Returns an array that represents the path from the top-level form to this control.
  4899. * Each index is the string name of the control on that level.
  4900. */
  4901. get: function () {
  4902. return this._parent ? controlPath(this.name, this._parent) : [this.name];
  4903. },
  4904. enumerable: true,
  4905. configurable: true
  4906. });
  4907. Object.defineProperty(NgModel.prototype, "formDirective", {
  4908. /**
  4909. * @description
  4910. * The top-level directive for this control if present, otherwise null.
  4911. */
  4912. get: function () { return this._parent ? this._parent.formDirective : null; },
  4913. enumerable: true,
  4914. configurable: true
  4915. });
  4916. Object.defineProperty(NgModel.prototype, "validator", {
  4917. /**
  4918. * @description
  4919. * Synchronous validator function composed of all the synchronous validators
  4920. * registered with this directive.
  4921. */
  4922. get: function () { return composeValidators(this._rawValidators); },
  4923. enumerable: true,
  4924. configurable: true
  4925. });
  4926. Object.defineProperty(NgModel.prototype, "asyncValidator", {
  4927. /**
  4928. * @description
  4929. * Async validator function composed of all the async validators registered with this
  4930. * directive.
  4931. */
  4932. get: function () {
  4933. return composeAsyncValidators(this._rawAsyncValidators);
  4934. },
  4935. enumerable: true,
  4936. configurable: true
  4937. });
  4938. /**
  4939. * @description
  4940. * Sets the new value for the view model and emits an `ngModelChange` event.
  4941. *
  4942. * @param newValue The new value emitted by `ngModelChange`.
  4943. */
  4944. NgModel.prototype.viewToModelUpdate = function (newValue) {
  4945. this.viewModel = newValue;
  4946. this.update.emit(newValue);
  4947. };
  4948. NgModel.prototype._setUpControl = function () {
  4949. this._setUpdateStrategy();
  4950. this._isStandalone() ? this._setUpStandalone() :
  4951. this.formDirective.addControl(this);
  4952. this._registered = true;
  4953. };
  4954. NgModel.prototype._setUpdateStrategy = function () {
  4955. if (this.options && this.options.updateOn != null) {
  4956. this.control._updateOn = this.options.updateOn;
  4957. }
  4958. };
  4959. NgModel.prototype._isStandalone = function () {
  4960. return !this._parent || !!(this.options && this.options.standalone);
  4961. };
  4962. NgModel.prototype._setUpStandalone = function () {
  4963. setUpControl(this.control, this);
  4964. this.control.updateValueAndValidity({ emitEvent: false });
  4965. };
  4966. NgModel.prototype._checkForErrors = function () {
  4967. if (!this._isStandalone()) {
  4968. this._checkParentType();
  4969. }
  4970. this._checkName();
  4971. };
  4972. NgModel.prototype._checkParentType = function () {
  4973. if (!(this._parent instanceof NgModelGroup) &&
  4974. this._parent instanceof AbstractFormGroupDirective) {
  4975. TemplateDrivenErrors.formGroupNameException();
  4976. }
  4977. else if (!(this._parent instanceof NgModelGroup) && !(this._parent instanceof NgForm)) {
  4978. TemplateDrivenErrors.modelParentException();
  4979. }
  4980. };
  4981. NgModel.prototype._checkName = function () {
  4982. if (this.options && this.options.name)
  4983. this.name = this.options.name;
  4984. if (!this._isStandalone() && !this.name) {
  4985. TemplateDrivenErrors.missingNameException();
  4986. }
  4987. };
  4988. NgModel.prototype._updateValue = function (value) {
  4989. var _this = this;
  4990. resolvedPromise$1.then(function () { _this.control.setValue(value, { emitViewToModelChange: false }); });
  4991. };
  4992. NgModel.prototype._updateDisabled = function (changes) {
  4993. var _this = this;
  4994. var disabledValue = changes['isDisabled'].currentValue;
  4995. var isDisabled = disabledValue === '' || (disabledValue && disabledValue !== 'false');
  4996. resolvedPromise$1.then(function () {
  4997. if (isDisabled && !_this.control.disabled) {
  4998. _this.control.disable();
  4999. }
  5000. else if (!isDisabled && _this.control.disabled) {
  5001. _this.control.enable();
  5002. }
  5003. });
  5004. };
  5005. __decorate([
  5006. core.Input(),
  5007. __metadata("design:type", String)
  5008. ], NgModel.prototype, "name", void 0);
  5009. __decorate([
  5010. core.Input('disabled'),
  5011. __metadata("design:type", Boolean)
  5012. ], NgModel.prototype, "isDisabled", void 0);
  5013. __decorate([
  5014. core.Input('ngModel'),
  5015. __metadata("design:type", Object)
  5016. ], NgModel.prototype, "model", void 0);
  5017. __decorate([
  5018. core.Input('ngModelOptions'),
  5019. __metadata("design:type", Object)
  5020. ], NgModel.prototype, "options", void 0);
  5021. __decorate([
  5022. core.Output('ngModelChange'),
  5023. __metadata("design:type", Object)
  5024. ], NgModel.prototype, "update", void 0);
  5025. NgModel = __decorate([
  5026. core.Directive({
  5027. selector: '[ngModel]:not([formControlName]):not([formControl])',
  5028. providers: [formControlBinding],
  5029. exportAs: 'ngModel'
  5030. }),
  5031. __param(0, core.Optional()), __param(0, core.Host()),
  5032. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_VALIDATORS)),
  5033. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_ASYNC_VALIDATORS)),
  5034. __param(3, core.Optional()), __param(3, core.Self()), __param(3, core.Inject(NG_VALUE_ACCESSOR)),
  5035. __metadata("design:paramtypes", [ControlContainer,
  5036. Array,
  5037. Array, Array])
  5038. ], NgModel);
  5039. return NgModel;
  5040. }(NgControl));
  5041. /**
  5042. * @license
  5043. * Copyright Google Inc. All Rights Reserved.
  5044. *
  5045. * Use of this source code is governed by an MIT-style license that can be
  5046. * found in the LICENSE file at https://angular.io/license
  5047. */
  5048. /**
  5049. * @description
  5050. *
  5051. * Adds `novalidate` attribute to all forms by default.
  5052. *
  5053. * `novalidate` is used to disable browser's native form validation.
  5054. *
  5055. * If you want to use native validation with Angular forms, just add `ngNativeValidate` attribute:
  5056. *
  5057. * ```
  5058. * <form ngNativeValidate></form>
  5059. * ```
  5060. *
  5061. * @publicApi
  5062. * @ngModule ReactiveFormsModule
  5063. * @ngModule FormsModule
  5064. */
  5065. var ɵNgNoValidate = /** @class */ (function () {
  5066. function ɵNgNoValidate() {
  5067. }
  5068. ɵNgNoValidate = __decorate([
  5069. core.Directive({
  5070. selector: 'form:not([ngNoForm]):not([ngNativeValidate])',
  5071. host: { 'novalidate': '' },
  5072. })
  5073. ], ɵNgNoValidate);
  5074. return ɵNgNoValidate;
  5075. }());
  5076. /**
  5077. * @license
  5078. * Copyright Google Inc. All Rights Reserved.
  5079. *
  5080. * Use of this source code is governed by an MIT-style license that can be
  5081. * found in the LICENSE file at https://angular.io/license
  5082. */
  5083. /**
  5084. * Token to provide to turn off the ngModel warning on formControl and formControlName.
  5085. */
  5086. var NG_MODEL_WITH_FORM_CONTROL_WARNING = new core.InjectionToken('NgModelWithFormControlWarning');
  5087. var formControlBinding$1 = {
  5088. provide: NgControl,
  5089. useExisting: core.forwardRef(function () { return FormControlDirective; })
  5090. };
  5091. /**
  5092. * @description
  5093. * * Syncs a standalone `FormControl` instance to a form control element.
  5094. *
  5095. * @see [Reactive Forms Guide](guide/reactive-forms)
  5096. * @see `FormControl`
  5097. * @see `AbstractControl`
  5098. *
  5099. * @usageNotes
  5100. *
  5101. * ### Registering a single form control
  5102. *
  5103. * The following examples shows how to register a standalone control and set its value.
  5104. *
  5105. * {@example forms/ts/simpleFormControl/simple_form_control_example.ts region='Component'}
  5106. *
  5107. * ### Use with ngModel
  5108. *
  5109. * Support for using the `ngModel` input property and `ngModelChange` event with reactive
  5110. * form directives has been deprecated in Angular v6 and will be removed in Angular v7.
  5111. *
  5112. * Now deprecated:
  5113. *
  5114. * ```html
  5115. * <input [formControl]="control" [(ngModel)]="value">
  5116. * ```
  5117. *
  5118. * ```ts
  5119. * this.value = 'some value';
  5120. * ```
  5121. *
  5122. * This has been deprecated for a few reasons. First, developers have found this pattern
  5123. * confusing. It seems like the actual `ngModel` directive is being used, but in fact it's
  5124. * an input/output property named `ngModel` on the reactive form directive that simply
  5125. * approximates (some of) its behavior. Specifically, it allows getting/setting the value
  5126. * and intercepting value events. However, some of `ngModel`'s other features - like
  5127. * delaying updates with`ngModelOptions` or exporting the directive - simply don't work,
  5128. * which has understandably caused some confusion.
  5129. *
  5130. * In addition, this pattern mixes template-driven and reactive forms strategies, which
  5131. * we generally don't recommend because it doesn't take advantage of the full benefits of
  5132. * either strategy. Setting the value in the template violates the template-agnostic
  5133. * principles behind reactive forms, whereas adding a `FormControl`/`FormGroup` layer in
  5134. * the class removes the convenience of defining forms in the template.
  5135. *
  5136. * To update your code before v7, you'll want to decide whether to stick with reactive form
  5137. * directives (and get/set values using reactive forms patterns) or switch over to
  5138. * template-driven directives.
  5139. *
  5140. * After (choice 1 - use reactive forms):
  5141. *
  5142. * ```html
  5143. * <input [formControl]="control">
  5144. * ```
  5145. *
  5146. * ```ts
  5147. * this.control.setValue('some value');
  5148. * ```
  5149. *
  5150. * After (choice 2 - use template-driven forms):
  5151. *
  5152. * ```html
  5153. * <input [(ngModel)]="value">
  5154. * ```
  5155. *
  5156. * ```ts
  5157. * this.value = 'some value';
  5158. * ```
  5159. *
  5160. * By default, when you use this pattern, you will see a deprecation warning once in dev
  5161. * mode. You can choose to silence this warning by providing a config for
  5162. * `ReactiveFormsModule` at import time:
  5163. *
  5164. * ```ts
  5165. * imports: [
  5166. * ReactiveFormsModule.withConfig({warnOnNgModelWithFormControl: 'never'});
  5167. * ]
  5168. * ```
  5169. *
  5170. * Alternatively, you can choose to surface a separate warning for each instance of this
  5171. * pattern with a config value of `"always"`. This may help to track down where in the code
  5172. * the pattern is being used as the code is being updated.
  5173. *
  5174. * @ngModule ReactiveFormsModule
  5175. * @publicApi
  5176. */
  5177. var FormControlDirective = /** @class */ (function (_super) {
  5178. __extends(FormControlDirective, _super);
  5179. function FormControlDirective(validators, asyncValidators, valueAccessors, _ngModelWarningConfig) {
  5180. var _this = _super.call(this) || this;
  5181. _this._ngModelWarningConfig = _ngModelWarningConfig;
  5182. /** @deprecated as of v6 */
  5183. _this.update = new core.EventEmitter();
  5184. /**
  5185. * @description
  5186. * Instance property used to track whether an ngModel warning has been sent out for this
  5187. * particular `FormControlDirective` instance. Used to support warning config of "always".
  5188. *
  5189. * @internal
  5190. */
  5191. _this._ngModelWarningSent = false;
  5192. _this._rawValidators = validators || [];
  5193. _this._rawAsyncValidators = asyncValidators || [];
  5194. _this.valueAccessor = selectValueAccessor(_this, valueAccessors);
  5195. return _this;
  5196. }
  5197. FormControlDirective_1 = FormControlDirective;
  5198. Object.defineProperty(FormControlDirective.prototype, "isDisabled", {
  5199. /**
  5200. * @description
  5201. * Triggers a warning that this input should not be used with reactive forms.
  5202. */
  5203. set: function (isDisabled) { ReactiveErrors.disabledAttrWarning(); },
  5204. enumerable: true,
  5205. configurable: true
  5206. });
  5207. /**
  5208. * @description
  5209. * A lifecycle method called when the directive's inputs change. For internal use
  5210. * only.
  5211. *
  5212. * @param changes A object of key/value pairs for the set of changed inputs.
  5213. */
  5214. FormControlDirective.prototype.ngOnChanges = function (changes) {
  5215. if (this._isControlChanged(changes)) {
  5216. setUpControl(this.form, this);
  5217. if (this.control.disabled && this.valueAccessor.setDisabledState) {
  5218. this.valueAccessor.setDisabledState(true);
  5219. }
  5220. this.form.updateValueAndValidity({ emitEvent: false });
  5221. }
  5222. if (isPropertyUpdated(changes, this.viewModel)) {
  5223. _ngModelWarning('formControl', FormControlDirective_1, this, this._ngModelWarningConfig);
  5224. this.form.setValue(this.model);
  5225. this.viewModel = this.model;
  5226. }
  5227. };
  5228. Object.defineProperty(FormControlDirective.prototype, "path", {
  5229. /**
  5230. * @description
  5231. * Returns an array that represents the path from the top-level form to this control.
  5232. * Each index is the string name of the control on that level.
  5233. */
  5234. get: function () { return []; },
  5235. enumerable: true,
  5236. configurable: true
  5237. });
  5238. Object.defineProperty(FormControlDirective.prototype, "validator", {
  5239. /**
  5240. * @description
  5241. * Synchronous validator function composed of all the synchronous validators
  5242. * registered with this directive.
  5243. */
  5244. get: function () { return composeValidators(this._rawValidators); },
  5245. enumerable: true,
  5246. configurable: true
  5247. });
  5248. Object.defineProperty(FormControlDirective.prototype, "asyncValidator", {
  5249. /**
  5250. * @description
  5251. * Async validator function composed of all the async validators registered with this
  5252. * directive.
  5253. */
  5254. get: function () {
  5255. return composeAsyncValidators(this._rawAsyncValidators);
  5256. },
  5257. enumerable: true,
  5258. configurable: true
  5259. });
  5260. Object.defineProperty(FormControlDirective.prototype, "control", {
  5261. /**
  5262. * @description
  5263. * The `FormControl` bound to this directive.
  5264. */
  5265. get: function () { return this.form; },
  5266. enumerable: true,
  5267. configurable: true
  5268. });
  5269. /**
  5270. * @description
  5271. * Sets the new value for the view model and emits an `ngModelChange` event.
  5272. *
  5273. * @param newValue The new value for the view model.
  5274. */
  5275. FormControlDirective.prototype.viewToModelUpdate = function (newValue) {
  5276. this.viewModel = newValue;
  5277. this.update.emit(newValue);
  5278. };
  5279. FormControlDirective.prototype._isControlChanged = function (changes) {
  5280. return changes.hasOwnProperty('form');
  5281. };
  5282. var FormControlDirective_1;
  5283. /**
  5284. * @description
  5285. * Static property used to track whether any ngModel warnings have been sent across
  5286. * all instances of FormControlDirective. Used to support warning config of "once".
  5287. *
  5288. * @internal
  5289. */
  5290. FormControlDirective._ngModelWarningSentOnce = false;
  5291. __decorate([
  5292. core.Input('formControl'),
  5293. __metadata("design:type", FormControl)
  5294. ], FormControlDirective.prototype, "form", void 0);
  5295. __decorate([
  5296. core.Input('disabled'),
  5297. __metadata("design:type", Boolean),
  5298. __metadata("design:paramtypes", [Boolean])
  5299. ], FormControlDirective.prototype, "isDisabled", null);
  5300. __decorate([
  5301. core.Input('ngModel'),
  5302. __metadata("design:type", Object)
  5303. ], FormControlDirective.prototype, "model", void 0);
  5304. __decorate([
  5305. core.Output('ngModelChange'),
  5306. __metadata("design:type", Object)
  5307. ], FormControlDirective.prototype, "update", void 0);
  5308. FormControlDirective = FormControlDirective_1 = __decorate([
  5309. core.Directive({ selector: '[formControl]', providers: [formControlBinding$1], exportAs: 'ngForm' }),
  5310. __param(0, core.Optional()), __param(0, core.Self()), __param(0, core.Inject(NG_VALIDATORS)),
  5311. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_ASYNC_VALIDATORS)),
  5312. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_VALUE_ACCESSOR)),
  5313. __param(3, core.Optional()), __param(3, core.Inject(NG_MODEL_WITH_FORM_CONTROL_WARNING)),
  5314. __metadata("design:paramtypes", [Array,
  5315. Array, Array, Object])
  5316. ], FormControlDirective);
  5317. return FormControlDirective;
  5318. }(NgControl));
  5319. /**
  5320. * @license
  5321. * Copyright Google Inc. All Rights Reserved.
  5322. *
  5323. * Use of this source code is governed by an MIT-style license that can be
  5324. * found in the LICENSE file at https://angular.io/license
  5325. */
  5326. var formDirectiveProvider$1 = {
  5327. provide: ControlContainer,
  5328. useExisting: core.forwardRef(function () { return FormGroupDirective; })
  5329. };
  5330. /**
  5331. * @description
  5332. *
  5333. * Binds an existing `FormGroup` to a DOM element.
  5334. *
  5335. * This directive accepts an existing `FormGroup` instance. It will then use this
  5336. * `FormGroup` instance to match any child `FormControl`, `FormGroup`,
  5337. * and `FormArray` instances to child `FormControlName`, `FormGroupName`,
  5338. * and `FormArrayName` directives.
  5339. *
  5340. * @see [Reactive Forms Guide](guide/reactive-forms)
  5341. * @see `AbstractControl`
  5342. *
  5343. * ### Register Form Group
  5344. *
  5345. * The following example registers a `FormGroup` with first name and last name controls,
  5346. * and listens for the *ngSubmit* event when the button is clicked.
  5347. *
  5348. * {@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
  5349. *
  5350. * @ngModule ReactiveFormsModule
  5351. * @publicApi
  5352. */
  5353. var FormGroupDirective = /** @class */ (function (_super) {
  5354. __extends(FormGroupDirective, _super);
  5355. function FormGroupDirective(_validators, _asyncValidators) {
  5356. var _this = _super.call(this) || this;
  5357. _this._validators = _validators;
  5358. _this._asyncValidators = _asyncValidators;
  5359. /**
  5360. * @description
  5361. * Reports whether the form submission has been triggered.
  5362. */
  5363. _this.submitted = false;
  5364. /**
  5365. * @description
  5366. * Tracks the list of added `FormControlName` instances
  5367. */
  5368. _this.directives = [];
  5369. /**
  5370. * @description
  5371. * Tracks the `FormGroup` bound to this directive.
  5372. */
  5373. _this.form = null;
  5374. /**
  5375. * @description
  5376. * Emits an event when the form submission has been triggered.
  5377. */
  5378. _this.ngSubmit = new core.EventEmitter();
  5379. return _this;
  5380. }
  5381. /**
  5382. * @description
  5383. * A lifecycle method called when the directive's inputs change. For internal use only.
  5384. *
  5385. * @param changes A object of key/value pairs for the set of changed inputs.
  5386. */
  5387. FormGroupDirective.prototype.ngOnChanges = function (changes) {
  5388. this._checkFormPresent();
  5389. if (changes.hasOwnProperty('form')) {
  5390. this._updateValidators();
  5391. this._updateDomValue();
  5392. this._updateRegistrations();
  5393. }
  5394. };
  5395. Object.defineProperty(FormGroupDirective.prototype, "formDirective", {
  5396. /**
  5397. * @description
  5398. * Returns this directive's instance.
  5399. */
  5400. get: function () { return this; },
  5401. enumerable: true,
  5402. configurable: true
  5403. });
  5404. Object.defineProperty(FormGroupDirective.prototype, "control", {
  5405. /**
  5406. * @description
  5407. * Returns the `FormGroup` bound to this directive.
  5408. */
  5409. get: function () { return this.form; },
  5410. enumerable: true,
  5411. configurable: true
  5412. });
  5413. Object.defineProperty(FormGroupDirective.prototype, "path", {
  5414. /**
  5415. * @description
  5416. * Returns an array representing the path to this group. Because this directive
  5417. * always lives at the top level of a form, it always an empty array.
  5418. */
  5419. get: function () { return []; },
  5420. enumerable: true,
  5421. configurable: true
  5422. });
  5423. /**
  5424. * @description
  5425. * Method that sets up the control directive in this group, re-calculates its value
  5426. * and validity, and adds the instance to the internal list of directives.
  5427. *
  5428. * @param dir The `FormControlName` directive instance.
  5429. */
  5430. FormGroupDirective.prototype.addControl = function (dir) {
  5431. var ctrl = this.form.get(dir.path);
  5432. setUpControl(ctrl, dir);
  5433. ctrl.updateValueAndValidity({ emitEvent: false });
  5434. this.directives.push(dir);
  5435. return ctrl;
  5436. };
  5437. /**
  5438. * @description
  5439. * Retrieves the `FormControl` instance from the provided `FormControlName` directive
  5440. *
  5441. * @param dir The `FormControlName` directive instance.
  5442. */
  5443. FormGroupDirective.prototype.getControl = function (dir) { return this.form.get(dir.path); };
  5444. /**
  5445. * @description
  5446. * Removes the `FormControlName` instance from the internal list of directives
  5447. *
  5448. * @param dir The `FormControlName` directive instance.
  5449. */
  5450. FormGroupDirective.prototype.removeControl = function (dir) { removeDir(this.directives, dir); };
  5451. /**
  5452. * Adds a new `FormGroupName` directive instance to the form.
  5453. *
  5454. * @param dir The `FormGroupName` directive instance.
  5455. */
  5456. FormGroupDirective.prototype.addFormGroup = function (dir) {
  5457. var ctrl = this.form.get(dir.path);
  5458. setUpFormContainer(ctrl, dir);
  5459. ctrl.updateValueAndValidity({ emitEvent: false });
  5460. };
  5461. /**
  5462. * No-op method to remove the form group.
  5463. *
  5464. * @param dir The `FormGroupName` directive instance.
  5465. */
  5466. FormGroupDirective.prototype.removeFormGroup = function (dir) { };
  5467. /**
  5468. * @description
  5469. * Retrieves the `FormGroup` for a provided `FormGroupName` directive instance
  5470. *
  5471. * @param dir The `FormGroupName` directive instance.
  5472. */
  5473. FormGroupDirective.prototype.getFormGroup = function (dir) { return this.form.get(dir.path); };
  5474. /**
  5475. * Adds a new `FormArrayName` directive instance to the form.
  5476. *
  5477. * @param dir The `FormArrayName` directive instance.
  5478. */
  5479. FormGroupDirective.prototype.addFormArray = function (dir) {
  5480. var ctrl = this.form.get(dir.path);
  5481. setUpFormContainer(ctrl, dir);
  5482. ctrl.updateValueAndValidity({ emitEvent: false });
  5483. };
  5484. /**
  5485. * No-op method to remove the form array.
  5486. *
  5487. * @param dir The `FormArrayName` directive instance.
  5488. */
  5489. FormGroupDirective.prototype.removeFormArray = function (dir) { };
  5490. /**
  5491. * @description
  5492. * Retrieves the `FormArray` for a provided `FormArrayName` directive instance.
  5493. *
  5494. * @param dir The `FormArrayName` directive instance.
  5495. */
  5496. FormGroupDirective.prototype.getFormArray = function (dir) { return this.form.get(dir.path); };
  5497. /**
  5498. * Sets the new value for the provided `FormControlName` directive.
  5499. *
  5500. * @param dir The `FormControlName` directive instance.
  5501. * @param value The new value for the directive's control.
  5502. */
  5503. FormGroupDirective.prototype.updateModel = function (dir, value) {
  5504. var ctrl = this.form.get(dir.path);
  5505. ctrl.setValue(value);
  5506. };
  5507. /**
  5508. * @description
  5509. * Method called with the "submit" event is triggered on the form.
  5510. * Triggers the `ngSubmit` emitter to emit the "submit" event as its payload.
  5511. *
  5512. * @param $event The "submit" event object
  5513. */
  5514. FormGroupDirective.prototype.onSubmit = function ($event) {
  5515. this.submitted = true;
  5516. syncPendingControls(this.form, this.directives);
  5517. this.ngSubmit.emit($event);
  5518. return false;
  5519. };
  5520. /**
  5521. * @description
  5522. * Method called when the "reset" event is triggered on the form.
  5523. */
  5524. FormGroupDirective.prototype.onReset = function () { this.resetForm(); };
  5525. /**
  5526. * @description
  5527. * Resets the form to an initial value and resets its submitted status.
  5528. *
  5529. * @param value The new value for the form.
  5530. */
  5531. FormGroupDirective.prototype.resetForm = function (value) {
  5532. if (value === void 0) { value = undefined; }
  5533. this.form.reset(value);
  5534. this.submitted = false;
  5535. };
  5536. /** @internal */
  5537. FormGroupDirective.prototype._updateDomValue = function () {
  5538. var _this = this;
  5539. this.directives.forEach(function (dir) {
  5540. var newCtrl = _this.form.get(dir.path);
  5541. if (dir.control !== newCtrl) {
  5542. cleanUpControl(dir.control, dir);
  5543. if (newCtrl)
  5544. setUpControl(newCtrl, dir);
  5545. dir.control = newCtrl;
  5546. }
  5547. });
  5548. this.form._updateTreeValidity({ emitEvent: false });
  5549. };
  5550. FormGroupDirective.prototype._updateRegistrations = function () {
  5551. var _this = this;
  5552. this.form._registerOnCollectionChange(function () { return _this._updateDomValue(); });
  5553. if (this._oldForm)
  5554. this._oldForm._registerOnCollectionChange(function () { });
  5555. this._oldForm = this.form;
  5556. };
  5557. FormGroupDirective.prototype._updateValidators = function () {
  5558. var sync = composeValidators(this._validators);
  5559. this.form.validator = Validators.compose([this.form.validator, sync]);
  5560. var async = composeAsyncValidators(this._asyncValidators);
  5561. this.form.asyncValidator = Validators.composeAsync([this.form.asyncValidator, async]);
  5562. };
  5563. FormGroupDirective.prototype._checkFormPresent = function () {
  5564. if (!this.form) {
  5565. ReactiveErrors.missingFormException();
  5566. }
  5567. };
  5568. __decorate([
  5569. core.Input('formGroup'),
  5570. __metadata("design:type", FormGroup)
  5571. ], FormGroupDirective.prototype, "form", void 0);
  5572. __decorate([
  5573. core.Output(),
  5574. __metadata("design:type", Object)
  5575. ], FormGroupDirective.prototype, "ngSubmit", void 0);
  5576. FormGroupDirective = __decorate([
  5577. core.Directive({
  5578. selector: '[formGroup]',
  5579. providers: [formDirectiveProvider$1],
  5580. host: { '(submit)': 'onSubmit($event)', '(reset)': 'onReset()' },
  5581. exportAs: 'ngForm'
  5582. }),
  5583. __param(0, core.Optional()), __param(0, core.Self()), __param(0, core.Inject(NG_VALIDATORS)),
  5584. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_ASYNC_VALIDATORS)),
  5585. __metadata("design:paramtypes", [Array, Array])
  5586. ], FormGroupDirective);
  5587. return FormGroupDirective;
  5588. }(ControlContainer));
  5589. /**
  5590. * @license
  5591. * Copyright Google Inc. All Rights Reserved.
  5592. *
  5593. * Use of this source code is governed by an MIT-style license that can be
  5594. * found in the LICENSE file at https://angular.io/license
  5595. */
  5596. var formGroupNameProvider = {
  5597. provide: ControlContainer,
  5598. useExisting: core.forwardRef(function () { return FormGroupName; })
  5599. };
  5600. /**
  5601. * @description
  5602. *
  5603. * Syncs a nested `FormGroup` to a DOM element.
  5604. *
  5605. * This directive can only be used with a parent `FormGroupDirective`.
  5606. *
  5607. * It accepts the string name of the nested `FormGroup` to link, and
  5608. * looks for a `FormGroup` registered with that name in the parent
  5609. * `FormGroup` instance you passed into `FormGroupDirective`.
  5610. *
  5611. * Use nested form groups to validate a sub-group of a
  5612. * form separately from the rest or to group the values of certain
  5613. * controls into their own nested object.
  5614. *
  5615. * @see [Reactive Forms Guide](guide/reactive-forms)
  5616. *
  5617. * @usageNotes
  5618. *
  5619. * ### Access the group by name
  5620. *
  5621. * The following example uses the {@link AbstractControl#get get} method to access the
  5622. * associated `FormGroup`
  5623. *
  5624. * ```ts
  5625. * this.form.get('name');
  5626. * ```
  5627. *
  5628. * ### Access individual controls in the group
  5629. *
  5630. * The following example uses the {@link AbstractControl#get get} method to access
  5631. * individual controls within the group using dot syntax.
  5632. *
  5633. * ```ts
  5634. * this.form.get('name.first');
  5635. * ```
  5636. *
  5637. * ### Register a nested `FormGroup`.
  5638. *
  5639. * The following example registers a nested *name* `FormGroup` within an existing `FormGroup`,
  5640. * and provides methods to retrieve the nested `FormGroup` and individual controls.
  5641. *
  5642. * {@example forms/ts/nestedFormGroup/nested_form_group_example.ts region='Component'}
  5643. *
  5644. * @ngModule ReactiveFormsModule
  5645. * @publicApi
  5646. */
  5647. var FormGroupName = /** @class */ (function (_super) {
  5648. __extends(FormGroupName, _super);
  5649. function FormGroupName(parent, validators, asyncValidators) {
  5650. var _this = _super.call(this) || this;
  5651. _this._parent = parent;
  5652. _this._validators = validators;
  5653. _this._asyncValidators = asyncValidators;
  5654. return _this;
  5655. }
  5656. /** @internal */
  5657. FormGroupName.prototype._checkParentType = function () {
  5658. if (_hasInvalidParent(this._parent)) {
  5659. ReactiveErrors.groupParentException();
  5660. }
  5661. };
  5662. __decorate([
  5663. core.Input('formGroupName'),
  5664. __metadata("design:type", String)
  5665. ], FormGroupName.prototype, "name", void 0);
  5666. FormGroupName = __decorate([
  5667. core.Directive({ selector: '[formGroupName]', providers: [formGroupNameProvider] }),
  5668. __param(0, core.Optional()), __param(0, core.Host()), __param(0, core.SkipSelf()),
  5669. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_VALIDATORS)),
  5670. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_ASYNC_VALIDATORS)),
  5671. __metadata("design:paramtypes", [ControlContainer, Array, Array])
  5672. ], FormGroupName);
  5673. return FormGroupName;
  5674. }(AbstractFormGroupDirective));
  5675. var formArrayNameProvider = {
  5676. provide: ControlContainer,
  5677. useExisting: core.forwardRef(function () { return FormArrayName; })
  5678. };
  5679. /**
  5680. * @description
  5681. *
  5682. * Syncs a nested `FormArray` to a DOM element.
  5683. *
  5684. * This directive is designed to be used with a parent `FormGroupDirective` (selector:
  5685. * `[formGroup]`).
  5686. *
  5687. * It accepts the string name of the nested `FormArray` you want to link, and
  5688. * will look for a `FormArray` registered with that name in the parent
  5689. * `FormGroup` instance you passed into `FormGroupDirective`.
  5690. *
  5691. * @see [Reactive Forms Guide](guide/reactive-forms)
  5692. * @see `AbstractControl`
  5693. *
  5694. * @usageNotes
  5695. *
  5696. * ### Example
  5697. *
  5698. * {@example forms/ts/nestedFormArray/nested_form_array_example.ts region='Component'}
  5699. *
  5700. * @ngModule ReactiveFormsModule
  5701. * @publicApi
  5702. */
  5703. var FormArrayName = /** @class */ (function (_super) {
  5704. __extends(FormArrayName, _super);
  5705. function FormArrayName(parent, validators, asyncValidators) {
  5706. var _this = _super.call(this) || this;
  5707. _this._parent = parent;
  5708. _this._validators = validators;
  5709. _this._asyncValidators = asyncValidators;
  5710. return _this;
  5711. }
  5712. /**
  5713. * @description
  5714. * A lifecycle method called when the directive's inputs are initialized. For internal use only.
  5715. *
  5716. * @throws If the directive does not have a valid parent.
  5717. */
  5718. FormArrayName.prototype.ngOnInit = function () {
  5719. this._checkParentType();
  5720. this.formDirective.addFormArray(this);
  5721. };
  5722. /**
  5723. * @description
  5724. * A lifecycle method called before the directive's instance is destroyed. For internal use only.
  5725. */
  5726. FormArrayName.prototype.ngOnDestroy = function () {
  5727. if (this.formDirective) {
  5728. this.formDirective.removeFormArray(this);
  5729. }
  5730. };
  5731. Object.defineProperty(FormArrayName.prototype, "control", {
  5732. /**
  5733. * @description
  5734. * The `FormArray` bound to this directive.
  5735. */
  5736. get: function () { return this.formDirective.getFormArray(this); },
  5737. enumerable: true,
  5738. configurable: true
  5739. });
  5740. Object.defineProperty(FormArrayName.prototype, "formDirective", {
  5741. /**
  5742. * @description
  5743. * The top-level directive for this group if present, otherwise null.
  5744. */
  5745. get: function () {
  5746. return this._parent ? this._parent.formDirective : null;
  5747. },
  5748. enumerable: true,
  5749. configurable: true
  5750. });
  5751. Object.defineProperty(FormArrayName.prototype, "path", {
  5752. /**
  5753. * @description
  5754. * Returns an array that represents the path from the top-level form to this control.
  5755. * Each index is the string name of the control on that level.
  5756. */
  5757. get: function () { return controlPath(this.name, this._parent); },
  5758. enumerable: true,
  5759. configurable: true
  5760. });
  5761. Object.defineProperty(FormArrayName.prototype, "validator", {
  5762. /**
  5763. * @description
  5764. * Synchronous validator function composed of all the synchronous validators registered with this
  5765. * directive.
  5766. */
  5767. get: function () { return composeValidators(this._validators); },
  5768. enumerable: true,
  5769. configurable: true
  5770. });
  5771. Object.defineProperty(FormArrayName.prototype, "asyncValidator", {
  5772. /**
  5773. * @description
  5774. * Async validator function composed of all the async validators registered with this directive.
  5775. */
  5776. get: function () {
  5777. return composeAsyncValidators(this._asyncValidators);
  5778. },
  5779. enumerable: true,
  5780. configurable: true
  5781. });
  5782. FormArrayName.prototype._checkParentType = function () {
  5783. if (_hasInvalidParent(this._parent)) {
  5784. ReactiveErrors.arrayParentException();
  5785. }
  5786. };
  5787. __decorate([
  5788. core.Input('formArrayName'),
  5789. __metadata("design:type", String)
  5790. ], FormArrayName.prototype, "name", void 0);
  5791. FormArrayName = __decorate([
  5792. core.Directive({ selector: '[formArrayName]', providers: [formArrayNameProvider] }),
  5793. __param(0, core.Optional()), __param(0, core.Host()), __param(0, core.SkipSelf()),
  5794. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_VALIDATORS)),
  5795. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_ASYNC_VALIDATORS)),
  5796. __metadata("design:paramtypes", [ControlContainer, Array, Array])
  5797. ], FormArrayName);
  5798. return FormArrayName;
  5799. }(ControlContainer));
  5800. function _hasInvalidParent(parent) {
  5801. return !(parent instanceof FormGroupName) && !(parent instanceof FormGroupDirective) &&
  5802. !(parent instanceof FormArrayName);
  5803. }
  5804. /**
  5805. * @license
  5806. * Copyright Google Inc. All Rights Reserved.
  5807. *
  5808. * Use of this source code is governed by an MIT-style license that can be
  5809. * found in the LICENSE file at https://angular.io/license
  5810. */
  5811. var controlNameBinding = {
  5812. provide: NgControl,
  5813. useExisting: core.forwardRef(function () { return FormControlName; })
  5814. };
  5815. /**
  5816. * @description
  5817. * Syncs a `FormControl` in an existing `FormGroup` to a form control
  5818. * element by name.
  5819. *
  5820. * @see [Reactive Forms Guide](guide/reactive-forms)
  5821. * @see `FormControl`
  5822. * @see `AbstractControl`
  5823. *
  5824. * @usageNotes
  5825. *
  5826. * ### Register `FormControl` within a group
  5827. *
  5828. * The following example shows how to register multiple form controls within a form group
  5829. * and set their value.
  5830. *
  5831. * {@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
  5832. *
  5833. * To see `formControlName` examples with different form control types, see:
  5834. *
  5835. * * Radio buttons: `RadioControlValueAccessor`
  5836. * * Selects: `SelectControlValueAccessor`
  5837. *
  5838. * ### Use with ngModel
  5839. *
  5840. * Support for using the `ngModel` input property and `ngModelChange` event with reactive
  5841. * form directives has been deprecated in Angular v6 and will be removed in Angular v7.
  5842. *
  5843. * Now deprecated:
  5844. *
  5845. * ```html
  5846. * <form [formGroup]="form">
  5847. * <input formControlName="first" [(ngModel)]="value">
  5848. * </form>
  5849. * ```
  5850. *
  5851. * ```ts
  5852. * this.value = 'some value';
  5853. * ```
  5854. *
  5855. * This has been deprecated for a few reasons. First, developers have found this pattern
  5856. * confusing. It seems like the actual `ngModel` directive is being used, but in fact it's
  5857. * an input/output property named `ngModel` on the reactive form directive that simply
  5858. * approximates (some of) its behavior. Specifically, it allows getting/setting the value
  5859. * and intercepting value events. However, some of `ngModel`'s other features - like
  5860. * delaying updates with`ngModelOptions` or exporting the directive - simply don't work,
  5861. * which has understandably caused some confusion.
  5862. *
  5863. * In addition, this pattern mixes template-driven and reactive forms strategies, which
  5864. * we generally don't recommend because it doesn't take advantage of the full benefits of
  5865. * either strategy. Setting the value in the template violates the template-agnostic
  5866. * principles behind reactive forms, whereas adding a `FormControl`/`FormGroup` layer in
  5867. * the class removes the convenience of defining forms in the template.
  5868. *
  5869. * To update your code before v7, you'll want to decide whether to stick with reactive form
  5870. * directives (and get/set values using reactive forms patterns) or switch over to
  5871. * template-driven directives.
  5872. *
  5873. * After (choice 1 - use reactive forms):
  5874. *
  5875. * ```html
  5876. * <form [formGroup]="form">
  5877. * <input formControlName="first">
  5878. * </form>
  5879. * ```
  5880. *
  5881. * ```ts
  5882. * this.form.get('first').setValue('some value');
  5883. * ```
  5884. *
  5885. * After (choice 2 - use template-driven forms):
  5886. *
  5887. * ```html
  5888. * <input [(ngModel)]="value">
  5889. * ```
  5890. *
  5891. * ```ts
  5892. * this.value = 'some value';
  5893. * ```
  5894. *
  5895. * By default, when you use this pattern, you will see a deprecation warning once in dev
  5896. * mode. You can choose to silence this warning by providing a config for
  5897. * `ReactiveFormsModule` at import time:
  5898. *
  5899. * ```ts
  5900. * imports: [
  5901. * ReactiveFormsModule.withConfig({warnOnNgModelWithFormControl: 'never'})
  5902. * ]
  5903. * ```
  5904. *
  5905. * Alternatively, you can choose to surface a separate warning for each instance of this
  5906. * pattern with a config value of `"always"`. This may help to track down where in the code
  5907. * the pattern is being used as the code is being updated.
  5908. *
  5909. * @ngModule ReactiveFormsModule
  5910. * @publicApi
  5911. */
  5912. var FormControlName = /** @class */ (function (_super) {
  5913. __extends(FormControlName, _super);
  5914. function FormControlName(parent, validators, asyncValidators, valueAccessors, _ngModelWarningConfig) {
  5915. var _this = _super.call(this) || this;
  5916. _this._ngModelWarningConfig = _ngModelWarningConfig;
  5917. _this._added = false;
  5918. /** @deprecated as of v6 */
  5919. _this.update = new core.EventEmitter();
  5920. /**
  5921. * @description
  5922. * Instance property used to track whether an ngModel warning has been sent out for this
  5923. * particular FormControlName instance. Used to support warning config of "always".
  5924. *
  5925. * @internal
  5926. */
  5927. _this._ngModelWarningSent = false;
  5928. _this._parent = parent;
  5929. _this._rawValidators = validators || [];
  5930. _this._rawAsyncValidators = asyncValidators || [];
  5931. _this.valueAccessor = selectValueAccessor(_this, valueAccessors);
  5932. return _this;
  5933. }
  5934. FormControlName_1 = FormControlName;
  5935. Object.defineProperty(FormControlName.prototype, "isDisabled", {
  5936. /**
  5937. * @description
  5938. * Triggers a warning that this input should not be used with reactive forms.
  5939. */
  5940. set: function (isDisabled) { ReactiveErrors.disabledAttrWarning(); },
  5941. enumerable: true,
  5942. configurable: true
  5943. });
  5944. /**
  5945. * @description
  5946. * A lifecycle method called when the directive's inputs change. For internal use only.
  5947. *
  5948. * @param changes A object of key/value pairs for the set of changed inputs.
  5949. */
  5950. FormControlName.prototype.ngOnChanges = function (changes) {
  5951. if (!this._added)
  5952. this._setUpControl();
  5953. if (isPropertyUpdated(changes, this.viewModel)) {
  5954. _ngModelWarning('formControlName', FormControlName_1, this, this._ngModelWarningConfig);
  5955. this.viewModel = this.model;
  5956. this.formDirective.updateModel(this, this.model);
  5957. }
  5958. };
  5959. /**
  5960. * @description
  5961. * Lifecycle method called before the directive's instance is destroyed. For internal use only.
  5962. */
  5963. FormControlName.prototype.ngOnDestroy = function () {
  5964. if (this.formDirective) {
  5965. this.formDirective.removeControl(this);
  5966. }
  5967. };
  5968. /**
  5969. * @description
  5970. * Sets the new value for the view model and emits an `ngModelChange` event.
  5971. *
  5972. * @param newValue The new value for the view model.
  5973. */
  5974. FormControlName.prototype.viewToModelUpdate = function (newValue) {
  5975. this.viewModel = newValue;
  5976. this.update.emit(newValue);
  5977. };
  5978. Object.defineProperty(FormControlName.prototype, "path", {
  5979. /**
  5980. * @description
  5981. * Returns an array that represents the path from the top-level form to this control.
  5982. * Each index is the string name of the control on that level.
  5983. */
  5984. get: function () { return controlPath(this.name, this._parent); },
  5985. enumerable: true,
  5986. configurable: true
  5987. });
  5988. Object.defineProperty(FormControlName.prototype, "formDirective", {
  5989. /**
  5990. * @description
  5991. * The top-level directive for this group if present, otherwise null.
  5992. */
  5993. get: function () { return this._parent ? this._parent.formDirective : null; },
  5994. enumerable: true,
  5995. configurable: true
  5996. });
  5997. Object.defineProperty(FormControlName.prototype, "validator", {
  5998. /**
  5999. * @description
  6000. * Synchronous validator function composed of all the synchronous validators
  6001. * registered with this directive.
  6002. */
  6003. get: function () { return composeValidators(this._rawValidators); },
  6004. enumerable: true,
  6005. configurable: true
  6006. });
  6007. Object.defineProperty(FormControlName.prototype, "asyncValidator", {
  6008. /**
  6009. * @description
  6010. * Async validator function composed of all the async validators registered with this
  6011. * directive.
  6012. */
  6013. get: function () {
  6014. return composeAsyncValidators(this._rawAsyncValidators);
  6015. },
  6016. enumerable: true,
  6017. configurable: true
  6018. });
  6019. FormControlName.prototype._checkParentType = function () {
  6020. if (!(this._parent instanceof FormGroupName) &&
  6021. this._parent instanceof AbstractFormGroupDirective) {
  6022. ReactiveErrors.ngModelGroupException();
  6023. }
  6024. else if (!(this._parent instanceof FormGroupName) && !(this._parent instanceof FormGroupDirective) &&
  6025. !(this._parent instanceof FormArrayName)) {
  6026. ReactiveErrors.controlParentException();
  6027. }
  6028. };
  6029. FormControlName.prototype._setUpControl = function () {
  6030. this._checkParentType();
  6031. this.control = this.formDirective.addControl(this);
  6032. if (this.control.disabled && this.valueAccessor.setDisabledState) {
  6033. this.valueAccessor.setDisabledState(true);
  6034. }
  6035. this._added = true;
  6036. };
  6037. var FormControlName_1;
  6038. /**
  6039. * @description
  6040. * Static property used to track whether any ngModel warnings have been sent across
  6041. * all instances of FormControlName. Used to support warning config of "once".
  6042. *
  6043. * @internal
  6044. */
  6045. FormControlName._ngModelWarningSentOnce = false;
  6046. __decorate([
  6047. core.Input('formControlName'),
  6048. __metadata("design:type", String)
  6049. ], FormControlName.prototype, "name", void 0);
  6050. __decorate([
  6051. core.Input('disabled'),
  6052. __metadata("design:type", Boolean),
  6053. __metadata("design:paramtypes", [Boolean])
  6054. ], FormControlName.prototype, "isDisabled", null);
  6055. __decorate([
  6056. core.Input('ngModel'),
  6057. __metadata("design:type", Object)
  6058. ], FormControlName.prototype, "model", void 0);
  6059. __decorate([
  6060. core.Output('ngModelChange'),
  6061. __metadata("design:type", Object)
  6062. ], FormControlName.prototype, "update", void 0);
  6063. FormControlName = FormControlName_1 = __decorate([
  6064. core.Directive({ selector: '[formControlName]', providers: [controlNameBinding] }),
  6065. __param(0, core.Optional()), __param(0, core.Host()), __param(0, core.SkipSelf()),
  6066. __param(1, core.Optional()), __param(1, core.Self()), __param(1, core.Inject(NG_VALIDATORS)),
  6067. __param(2, core.Optional()), __param(2, core.Self()), __param(2, core.Inject(NG_ASYNC_VALIDATORS)),
  6068. __param(3, core.Optional()), __param(3, core.Self()), __param(3, core.Inject(NG_VALUE_ACCESSOR)),
  6069. __param(4, core.Optional()), __param(4, core.Inject(NG_MODEL_WITH_FORM_CONTROL_WARNING)),
  6070. __metadata("design:paramtypes", [ControlContainer,
  6071. Array,
  6072. Array, Array, Object])
  6073. ], FormControlName);
  6074. return FormControlName;
  6075. }(NgControl));
  6076. /**
  6077. * @license
  6078. * Copyright Google Inc. All Rights Reserved.
  6079. *
  6080. * Use of this source code is governed by an MIT-style license that can be
  6081. * found in the LICENSE file at https://angular.io/license
  6082. */
  6083. /**
  6084. * @description
  6085. * Provider which adds `RequiredValidator` to the `NG_VALIDATORS` multi-provider list.
  6086. */
  6087. var REQUIRED_VALIDATOR = {
  6088. provide: NG_VALIDATORS,
  6089. useExisting: core.forwardRef(function () { return RequiredValidator; }),
  6090. multi: true
  6091. };
  6092. /**
  6093. * @description
  6094. * Provider which adds `CheckboxRequiredValidator` to the `NG_VALIDATORS` multi-provider list.
  6095. */
  6096. var CHECKBOX_REQUIRED_VALIDATOR = {
  6097. provide: NG_VALIDATORS,
  6098. useExisting: core.forwardRef(function () { return CheckboxRequiredValidator; }),
  6099. multi: true
  6100. };
  6101. /**
  6102. * @description
  6103. * A directive that adds the `required` validator to any controls marked with the
  6104. * `required` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  6105. *
  6106. * @see [Form Validation](guide/form-validation)
  6107. *
  6108. * @usageNotes
  6109. *
  6110. * ### Adding a required validator using template-driven forms
  6111. *
  6112. * ```
  6113. * <input name="fullName" ngModel required>
  6114. * ```
  6115. *
  6116. * @ngModule FormsModule
  6117. * @ngModule ReactiveFormsModule
  6118. * @publicApi
  6119. */
  6120. var RequiredValidator = /** @class */ (function () {
  6121. function RequiredValidator() {
  6122. }
  6123. Object.defineProperty(RequiredValidator.prototype, "required", {
  6124. /**
  6125. * @description
  6126. * Tracks changes to the required attribute bound to this directive.
  6127. */
  6128. get: function () { return this._required; },
  6129. set: function (value) {
  6130. this._required = value != null && value !== false && "" + value !== 'false';
  6131. if (this._onChange)
  6132. this._onChange();
  6133. },
  6134. enumerable: true,
  6135. configurable: true
  6136. });
  6137. /**
  6138. * @description
  6139. * Method that validates whether the control is empty.
  6140. * Returns the validation result if enabled, otherwise null.
  6141. */
  6142. RequiredValidator.prototype.validate = function (control) {
  6143. return this.required ? Validators.required(control) : null;
  6144. };
  6145. /**
  6146. * @description
  6147. * Registers a callback function to call when the validator inputs change.
  6148. *
  6149. * @param fn The callback function
  6150. */
  6151. RequiredValidator.prototype.registerOnValidatorChange = function (fn) { this._onChange = fn; };
  6152. __decorate([
  6153. core.Input(),
  6154. __metadata("design:type", Object),
  6155. __metadata("design:paramtypes", [Object])
  6156. ], RequiredValidator.prototype, "required", null);
  6157. RequiredValidator = __decorate([
  6158. core.Directive({
  6159. selector: ':not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]',
  6160. providers: [REQUIRED_VALIDATOR],
  6161. host: { '[attr.required]': 'required ? "" : null' }
  6162. })
  6163. ], RequiredValidator);
  6164. return RequiredValidator;
  6165. }());
  6166. /**
  6167. * A Directive that adds the `required` validator to checkbox controls marked with the
  6168. * `required` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  6169. *
  6170. * @see [Form Validation](guide/form-validation)
  6171. *
  6172. * @usageNotes
  6173. *
  6174. * ### Adding a required checkbox validator using template-driven forms
  6175. *
  6176. * The following example shows how to add a checkbox required validator to an input attached to an ngModel binding.
  6177. *
  6178. * ```
  6179. * <input type="checkbox" name="active" ngModel required>
  6180. * ```
  6181. *
  6182. * @publicApi
  6183. * @ngModule FormsModule
  6184. * @ngModule ReactiveFormsModule
  6185. */
  6186. var CheckboxRequiredValidator = /** @class */ (function (_super) {
  6187. __extends(CheckboxRequiredValidator, _super);
  6188. function CheckboxRequiredValidator() {
  6189. return _super !== null && _super.apply(this, arguments) || this;
  6190. }
  6191. /**
  6192. * @description
  6193. * Method that validates whether or not the checkbox has been checked.
  6194. * Returns the validation result if enabled, otherwise null.
  6195. */
  6196. CheckboxRequiredValidator.prototype.validate = function (control) {
  6197. return this.required ? Validators.requiredTrue(control) : null;
  6198. };
  6199. CheckboxRequiredValidator = __decorate([
  6200. core.Directive({
  6201. selector: 'input[type=checkbox][required][formControlName],input[type=checkbox][required][formControl],input[type=checkbox][required][ngModel]',
  6202. providers: [CHECKBOX_REQUIRED_VALIDATOR],
  6203. host: { '[attr.required]': 'required ? "" : null' }
  6204. })
  6205. ], CheckboxRequiredValidator);
  6206. return CheckboxRequiredValidator;
  6207. }(RequiredValidator));
  6208. /**
  6209. * @description
  6210. * Provider which adds `EmailValidator` to the `NG_VALIDATORS` multi-provider list.
  6211. */
  6212. var EMAIL_VALIDATOR = {
  6213. provide: NG_VALIDATORS,
  6214. useExisting: core.forwardRef(function () { return EmailValidator; }),
  6215. multi: true
  6216. };
  6217. /**
  6218. * A directive that adds the `email` validator to controls marked with the
  6219. * `email` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  6220. *
  6221. * @see [Form Validation](guide/form-validation)
  6222. *
  6223. * @usageNotes
  6224. *
  6225. * ### Adding an email validator
  6226. *
  6227. * The following example shows how to add an email validator to an input attached to an ngModel binding.
  6228. *
  6229. * ```
  6230. * <input type="email" name="email" ngModel email>
  6231. * <input type="email" name="email" ngModel email="true">
  6232. * <input type="email" name="email" ngModel [email]="true">
  6233. * ```
  6234. *
  6235. * @publicApi
  6236. * @ngModule FormsModule
  6237. * @ngModule ReactiveFormsModule
  6238. */
  6239. var EmailValidator = /** @class */ (function () {
  6240. function EmailValidator() {
  6241. }
  6242. Object.defineProperty(EmailValidator.prototype, "email", {
  6243. /**
  6244. * @description
  6245. * Tracks changes to the email attribute bound to this directive.
  6246. */
  6247. set: function (value) {
  6248. this._enabled = value === '' || value === true || value === 'true';
  6249. if (this._onChange)
  6250. this._onChange();
  6251. },
  6252. enumerable: true,
  6253. configurable: true
  6254. });
  6255. /**
  6256. * @description
  6257. * Method that validates whether an email address is valid.
  6258. * Returns the validation result if enabled, otherwise null.
  6259. */
  6260. EmailValidator.prototype.validate = function (control) {
  6261. return this._enabled ? Validators.email(control) : null;
  6262. };
  6263. /**
  6264. * @description
  6265. * Registers a callback function to call when the validator inputs change.
  6266. *
  6267. * @param fn The callback function
  6268. */
  6269. EmailValidator.prototype.registerOnValidatorChange = function (fn) { this._onChange = fn; };
  6270. __decorate([
  6271. core.Input(),
  6272. __metadata("design:type", Object),
  6273. __metadata("design:paramtypes", [Object])
  6274. ], EmailValidator.prototype, "email", null);
  6275. EmailValidator = __decorate([
  6276. core.Directive({
  6277. selector: '[email][formControlName],[email][formControl],[email][ngModel]',
  6278. providers: [EMAIL_VALIDATOR]
  6279. })
  6280. ], EmailValidator);
  6281. return EmailValidator;
  6282. }());
  6283. /**
  6284. * @description
  6285. * Provider which adds `MinLengthValidator` to the `NG_VALIDATORS` multi-provider list.
  6286. */
  6287. var MIN_LENGTH_VALIDATOR = {
  6288. provide: NG_VALIDATORS,
  6289. useExisting: core.forwardRef(function () { return MinLengthValidator; }),
  6290. multi: true
  6291. };
  6292. /**
  6293. * A directive that adds minimum length validation to controls marked with the
  6294. * `minlength` attribute. The directive is provided with the `NG_VALIDATORS` mult-provider list.
  6295. *
  6296. * @see [Form Validation](guide/form-validation)
  6297. *
  6298. * @usageNotes
  6299. *
  6300. * ### Adding a minimum length validator
  6301. *
  6302. * The following example shows how to add a minimum length validator to an input attached to an
  6303. * ngModel binding.
  6304. *
  6305. * ```html
  6306. * <input name="firstName" ngModel minlength="4">
  6307. * ```
  6308. *
  6309. * @ngModule ReactiveFormsModule
  6310. * @ngModule FormsModule
  6311. * @publicApi
  6312. */
  6313. var MinLengthValidator = /** @class */ (function () {
  6314. function MinLengthValidator() {
  6315. }
  6316. /**
  6317. * @description
  6318. * A lifecycle method called when the directive's inputs change. For internal use
  6319. * only.
  6320. *
  6321. * @param changes A object of key/value pairs for the set of changed inputs.
  6322. */
  6323. MinLengthValidator.prototype.ngOnChanges = function (changes) {
  6324. if ('minlength' in changes) {
  6325. this._createValidator();
  6326. if (this._onChange)
  6327. this._onChange();
  6328. }
  6329. };
  6330. /**
  6331. * @description
  6332. * Method that validates whether the value meets a minimum length
  6333. * requirement. Returns the validation result if enabled, otherwise null.
  6334. */
  6335. MinLengthValidator.prototype.validate = function (control) {
  6336. return this.minlength == null ? null : this._validator(control);
  6337. };
  6338. /**
  6339. * @description
  6340. * Registers a callback function to call when the validator inputs change.
  6341. *
  6342. * @param fn The callback function
  6343. */
  6344. MinLengthValidator.prototype.registerOnValidatorChange = function (fn) { this._onChange = fn; };
  6345. MinLengthValidator.prototype._createValidator = function () {
  6346. this._validator = Validators.minLength(parseInt(this.minlength, 10));
  6347. };
  6348. __decorate([
  6349. core.Input(),
  6350. __metadata("design:type", String)
  6351. ], MinLengthValidator.prototype, "minlength", void 0);
  6352. MinLengthValidator = __decorate([
  6353. core.Directive({
  6354. selector: '[minlength][formControlName],[minlength][formControl],[minlength][ngModel]',
  6355. providers: [MIN_LENGTH_VALIDATOR],
  6356. host: { '[attr.minlength]': 'minlength ? minlength : null' }
  6357. })
  6358. ], MinLengthValidator);
  6359. return MinLengthValidator;
  6360. }());
  6361. /**
  6362. * @description
  6363. * Provider which adds `MaxLengthValidator` to the `NG_VALIDATORS` multi-provider list.
  6364. */
  6365. var MAX_LENGTH_VALIDATOR = {
  6366. provide: NG_VALIDATORS,
  6367. useExisting: core.forwardRef(function () { return MaxLengthValidator; }),
  6368. multi: true
  6369. };
  6370. /**
  6371. * A directive that adds max length validation to controls marked with the
  6372. * `maxlength` attribute. The directive is provided with the `NG_VALIDATORS` multi-provider list.
  6373. *
  6374. * @see [Form Validation](guide/form-validation)
  6375. *
  6376. * @usageNotes
  6377. *
  6378. * ### Adding a maximum length validator
  6379. *
  6380. * The following example shows how to add a maximum length validator to an input attached to an
  6381. * ngModel binding.
  6382. *
  6383. * ```html
  6384. * <input name="firstName" ngModel maxlength="25">
  6385. * ```
  6386. *
  6387. * @ngModule ReactiveFormsModule
  6388. * @ngModule FormsModule
  6389. * @publicApi
  6390. */
  6391. var MaxLengthValidator = /** @class */ (function () {
  6392. function MaxLengthValidator() {
  6393. }
  6394. /**
  6395. * @description
  6396. * A lifecycle method called when the directive's inputs change. For internal use
  6397. * only.
  6398. *
  6399. * @param changes A object of key/value pairs for the set of changed inputs.
  6400. */
  6401. MaxLengthValidator.prototype.ngOnChanges = function (changes) {
  6402. if ('maxlength' in changes) {
  6403. this._createValidator();
  6404. if (this._onChange)
  6405. this._onChange();
  6406. }
  6407. };
  6408. /**
  6409. * @description
  6410. * Method that validates whether the value exceeds
  6411. * the maximum length requirement.
  6412. */
  6413. MaxLengthValidator.prototype.validate = function (control) {
  6414. return this.maxlength != null ? this._validator(control) : null;
  6415. };
  6416. /**
  6417. * @description
  6418. * Registers a callback function to call when the validator inputs change.
  6419. *
  6420. * @param fn The callback function
  6421. */
  6422. MaxLengthValidator.prototype.registerOnValidatorChange = function (fn) { this._onChange = fn; };
  6423. MaxLengthValidator.prototype._createValidator = function () {
  6424. this._validator = Validators.maxLength(parseInt(this.maxlength, 10));
  6425. };
  6426. __decorate([
  6427. core.Input(),
  6428. __metadata("design:type", String)
  6429. ], MaxLengthValidator.prototype, "maxlength", void 0);
  6430. MaxLengthValidator = __decorate([
  6431. core.Directive({
  6432. selector: '[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]',
  6433. providers: [MAX_LENGTH_VALIDATOR],
  6434. host: { '[attr.maxlength]': 'maxlength ? maxlength : null' }
  6435. })
  6436. ], MaxLengthValidator);
  6437. return MaxLengthValidator;
  6438. }());
  6439. /**
  6440. * @description
  6441. * Provider which adds `PatternValidator` to the `NG_VALIDATORS` multi-provider list.
  6442. */
  6443. var PATTERN_VALIDATOR = {
  6444. provide: NG_VALIDATORS,
  6445. useExisting: core.forwardRef(function () { return PatternValidator; }),
  6446. multi: true
  6447. };
  6448. /**
  6449. * @description
  6450. * A directive that adds regex pattern validation to controls marked with the
  6451. * `pattern` attribute. The regex must match the entire control value.
  6452. * The directive is provided with the `NG_VALIDATORS` multi-provider list.
  6453. *
  6454. * @see [Form Validation](guide/form-validation)
  6455. *
  6456. * @usageNotes
  6457. *
  6458. * ### Adding a pattern validator
  6459. *
  6460. * The following example shows how to add a pattern validator to an input attached to an
  6461. * ngModel binding.
  6462. *
  6463. * ```html
  6464. * <input name="firstName" ngModel pattern="[a-zA-Z ]*">
  6465. * ```
  6466. *
  6467. * @ngModule ReactiveFormsModule
  6468. * @ngModule FormsModule
  6469. * @publicApi
  6470. */
  6471. var PatternValidator = /** @class */ (function () {
  6472. function PatternValidator() {
  6473. }
  6474. /**
  6475. * @description
  6476. * A lifecycle method called when the directive's inputs change. For internal use
  6477. * only.
  6478. *
  6479. * @param changes A object of key/value pairs for the set of changed inputs.
  6480. */
  6481. PatternValidator.prototype.ngOnChanges = function (changes) {
  6482. if ('pattern' in changes) {
  6483. this._createValidator();
  6484. if (this._onChange)
  6485. this._onChange();
  6486. }
  6487. };
  6488. /**
  6489. * @description
  6490. * Method that validates whether the value matches the
  6491. * the pattern requirement.
  6492. */
  6493. PatternValidator.prototype.validate = function (control) { return this._validator(control); };
  6494. /**
  6495. * @description
  6496. * Registers a callback function to call when the validator inputs change.
  6497. *
  6498. * @param fn The callback function
  6499. */
  6500. PatternValidator.prototype.registerOnValidatorChange = function (fn) { this._onChange = fn; };
  6501. PatternValidator.prototype._createValidator = function () { this._validator = Validators.pattern(this.pattern); };
  6502. __decorate([
  6503. core.Input(),
  6504. __metadata("design:type", Object)
  6505. ], PatternValidator.prototype, "pattern", void 0);
  6506. PatternValidator = __decorate([
  6507. core.Directive({
  6508. selector: '[pattern][formControlName],[pattern][formControl],[pattern][ngModel]',
  6509. providers: [PATTERN_VALIDATOR],
  6510. host: { '[attr.pattern]': 'pattern ? pattern : null' }
  6511. })
  6512. ], PatternValidator);
  6513. return PatternValidator;
  6514. }());
  6515. /**
  6516. * @license
  6517. * Copyright Google Inc. All Rights Reserved.
  6518. *
  6519. * Use of this source code is governed by an MIT-style license that can be
  6520. * found in the LICENSE file at https://angular.io/license
  6521. */
  6522. var SHARED_FORM_DIRECTIVES = [
  6523. ɵNgNoValidate,
  6524. NgSelectOption,
  6525. ɵNgSelectMultipleOption,
  6526. DefaultValueAccessor,
  6527. NumberValueAccessor,
  6528. RangeValueAccessor,
  6529. CheckboxControlValueAccessor,
  6530. SelectControlValueAccessor,
  6531. SelectMultipleControlValueAccessor,
  6532. RadioControlValueAccessor,
  6533. NgControlStatus,
  6534. NgControlStatusGroup,
  6535. RequiredValidator,
  6536. MinLengthValidator,
  6537. MaxLengthValidator,
  6538. PatternValidator,
  6539. CheckboxRequiredValidator,
  6540. EmailValidator,
  6541. ];
  6542. var TEMPLATE_DRIVEN_DIRECTIVES = [NgModel, NgModelGroup, NgForm, NgFormSelectorWarning];
  6543. var REACTIVE_DRIVEN_DIRECTIVES = [FormControlDirective, FormGroupDirective, FormControlName, FormGroupName, FormArrayName];
  6544. /**
  6545. * Internal module used for sharing directives between FormsModule and ReactiveFormsModule
  6546. */
  6547. var ɵInternalFormsSharedModule = /** @class */ (function () {
  6548. function ɵInternalFormsSharedModule() {
  6549. }
  6550. ɵInternalFormsSharedModule = __decorate([
  6551. core.NgModule({
  6552. declarations: SHARED_FORM_DIRECTIVES,
  6553. exports: SHARED_FORM_DIRECTIVES,
  6554. })
  6555. ], ɵInternalFormsSharedModule);
  6556. return ɵInternalFormsSharedModule;
  6557. }());
  6558. /**
  6559. * @license
  6560. * Copyright Google Inc. All Rights Reserved.
  6561. *
  6562. * Use of this source code is governed by an MIT-style license that can be
  6563. * found in the LICENSE file at https://angular.io/license
  6564. */
  6565. function isAbstractControlOptions(options) {
  6566. return options.asyncValidators !== undefined ||
  6567. options.validators !== undefined ||
  6568. options.updateOn !== undefined;
  6569. }
  6570. /**
  6571. * @description
  6572. * Creates an `AbstractControl` from a user-specified configuration.
  6573. *
  6574. * The `FormBuilder` provides syntactic sugar that shortens creating instances of a `FormControl`,
  6575. * `FormGroup`, or `FormArray`. It reduces the amount of boilerplate needed to build complex
  6576. * forms.
  6577. *
  6578. * @see [Reactive Forms Guide](/guide/reactive-forms)
  6579. *
  6580. * @publicApi
  6581. */
  6582. var FormBuilder = /** @class */ (function () {
  6583. function FormBuilder() {
  6584. }
  6585. /**
  6586. * @description
  6587. * Construct a new `FormGroup` instance.
  6588. *
  6589. * @param controlsConfig A collection of child controls. The key for each child is the name
  6590. * under which it is registered.
  6591. *
  6592. * @param options Configuration options object for the `FormGroup`. The object can
  6593. * have two shapes:
  6594. *
  6595. * 1) `AbstractControlOptions` object (preferred), which consists of:
  6596. * * `validators`: A synchronous validator function, or an array of validator functions
  6597. * * `asyncValidators`: A single async validator or array of async validator functions
  6598. * * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur' |
  6599. * submit')
  6600. *
  6601. * 2) Legacy configuration object, which consists of:
  6602. * * `validator`: A synchronous validator function, or an array of validator functions
  6603. * * `asyncValidator`: A single async validator or array of async validator functions
  6604. *
  6605. */
  6606. FormBuilder.prototype.group = function (controlsConfig, options) {
  6607. if (options === void 0) { options = null; }
  6608. var controls = this._reduceControls(controlsConfig);
  6609. var validators = null;
  6610. var asyncValidators = null;
  6611. var updateOn = undefined;
  6612. if (options != null) {
  6613. if (isAbstractControlOptions(options)) {
  6614. // `options` are `AbstractControlOptions`
  6615. validators = options.validators != null ? options.validators : null;
  6616. asyncValidators = options.asyncValidators != null ? options.asyncValidators : null;
  6617. updateOn = options.updateOn != null ? options.updateOn : undefined;
  6618. }
  6619. else {
  6620. // `options` are legacy form group options
  6621. validators = options['validator'] != null ? options['validator'] : null;
  6622. asyncValidators = options['asyncValidator'] != null ? options['asyncValidator'] : null;
  6623. }
  6624. }
  6625. return new FormGroup(controls, { asyncValidators: asyncValidators, updateOn: updateOn, validators: validators });
  6626. };
  6627. /**
  6628. * @description
  6629. * Construct a new `FormControl` with the given state, validators and options.
  6630. *
  6631. * @param formState Initializes the control with an initial state value, or
  6632. * with an object that contains both a value and a disabled status.
  6633. *
  6634. * @param validatorOrOpts A synchronous validator function, or an array of
  6635. * such functions, or an `AbstractControlOptions` object that contains
  6636. * validation functions and a validation trigger.
  6637. *
  6638. * @param asyncValidator A single async validator or array of async validator
  6639. * functions.
  6640. *
  6641. * @usageNotes
  6642. *
  6643. * ### Initialize a control as disabled
  6644. *
  6645. * The following example returns a control with an initial value in a disabled state.
  6646. *
  6647. * <code-example path="forms/ts/formBuilder/form_builder_example.ts"
  6648. * linenums="false" region="disabled-control">
  6649. * </code-example>
  6650. */
  6651. FormBuilder.prototype.control = function (formState, validatorOrOpts, asyncValidator) {
  6652. return new FormControl(formState, validatorOrOpts, asyncValidator);
  6653. };
  6654. /**
  6655. * Constructs a new `FormArray` from the given array of configurations,
  6656. * validators and options.
  6657. *
  6658. * @param controlsConfig An array of child controls or control configs. Each
  6659. * child control is given an index when it is registered.
  6660. *
  6661. * @param validatorOrOpts A synchronous validator function, or an array of
  6662. * such functions, or an `AbstractControlOptions` object that contains
  6663. * validation functions and a validation trigger.
  6664. *
  6665. * @param asyncValidator A single async validator or array of async validator
  6666. * functions.
  6667. */
  6668. FormBuilder.prototype.array = function (controlsConfig, validatorOrOpts, asyncValidator) {
  6669. var _this = this;
  6670. var controls = controlsConfig.map(function (c) { return _this._createControl(c); });
  6671. return new FormArray(controls, validatorOrOpts, asyncValidator);
  6672. };
  6673. /** @internal */
  6674. FormBuilder.prototype._reduceControls = function (controlsConfig) {
  6675. var _this = this;
  6676. var controls = {};
  6677. Object.keys(controlsConfig).forEach(function (controlName) {
  6678. controls[controlName] = _this._createControl(controlsConfig[controlName]);
  6679. });
  6680. return controls;
  6681. };
  6682. /** @internal */
  6683. FormBuilder.prototype._createControl = function (controlConfig) {
  6684. if (controlConfig instanceof FormControl || controlConfig instanceof FormGroup ||
  6685. controlConfig instanceof FormArray) {
  6686. return controlConfig;
  6687. }
  6688. else if (Array.isArray(controlConfig)) {
  6689. var value = controlConfig[0];
  6690. var validator = controlConfig.length > 1 ? controlConfig[1] : null;
  6691. var asyncValidator = controlConfig.length > 2 ? controlConfig[2] : null;
  6692. return this.control(value, validator, asyncValidator);
  6693. }
  6694. else {
  6695. return this.control(controlConfig);
  6696. }
  6697. };
  6698. FormBuilder = __decorate([
  6699. core.Injectable()
  6700. ], FormBuilder);
  6701. return FormBuilder;
  6702. }());
  6703. /**
  6704. * @license
  6705. * Copyright Google Inc. All Rights Reserved.
  6706. *
  6707. * Use of this source code is governed by an MIT-style license that can be
  6708. * found in the LICENSE file at https://angular.io/license
  6709. */
  6710. /**
  6711. * @publicApi
  6712. */
  6713. var VERSION = new core.Version('8.1.0');
  6714. /**
  6715. * @license
  6716. * Copyright Google Inc. All Rights Reserved.
  6717. *
  6718. * Use of this source code is governed by an MIT-style license that can be
  6719. * found in the LICENSE file at https://angular.io/license
  6720. */
  6721. /**
  6722. * Exports the required providers and directives for template-driven forms,
  6723. * making them available for import by NgModules that import this module.
  6724. *
  6725. * @see [Forms Guide](/guide/forms)
  6726. *
  6727. * @publicApi
  6728. */
  6729. var FormsModule = /** @class */ (function () {
  6730. function FormsModule() {
  6731. }
  6732. FormsModule_1 = FormsModule;
  6733. /**
  6734. * @description
  6735. * Provides options for configuring the template-driven forms module.
  6736. *
  6737. * @param opts An object of configuration options
  6738. * * `warnOnDeprecatedNgFormSelector` Configures when to emit a warning when the deprecated
  6739. * `ngForm` selector is used.
  6740. */
  6741. FormsModule.withConfig = function (opts) {
  6742. return {
  6743. ngModule: FormsModule_1,
  6744. providers: [{ provide: NG_FORM_SELECTOR_WARNING, useValue: opts.warnOnDeprecatedNgFormSelector }]
  6745. };
  6746. };
  6747. var FormsModule_1;
  6748. FormsModule = FormsModule_1 = __decorate([
  6749. core.NgModule({
  6750. declarations: TEMPLATE_DRIVEN_DIRECTIVES,
  6751. providers: [RadioControlRegistry],
  6752. exports: [ɵInternalFormsSharedModule, TEMPLATE_DRIVEN_DIRECTIVES]
  6753. })
  6754. ], FormsModule);
  6755. return FormsModule;
  6756. }());
  6757. /**
  6758. * Exports the required infrastructure and directives for reactive forms,
  6759. * making them available for import by NgModules that import this module.
  6760. * @see [Forms](guide/reactive-forms)
  6761. *
  6762. * @see [Reactive Forms Guide](/guide/reactive-forms)
  6763. *
  6764. * @publicApi
  6765. */
  6766. var ReactiveFormsModule = /** @class */ (function () {
  6767. function ReactiveFormsModule() {
  6768. }
  6769. ReactiveFormsModule_1 = ReactiveFormsModule;
  6770. /**
  6771. * @description
  6772. * Provides options for configuring the reactive forms module.
  6773. *
  6774. * @param opts An object of configuration options
  6775. * * `warnOnNgModelWithFormControl` Configures when to emit a warning when an `ngModel`
  6776. * binding is used with reactive form directives.
  6777. */
  6778. ReactiveFormsModule.withConfig = function (opts) {
  6779. return {
  6780. ngModule: ReactiveFormsModule_1,
  6781. providers: [{
  6782. provide: NG_MODEL_WITH_FORM_CONTROL_WARNING,
  6783. useValue: opts.warnOnNgModelWithFormControl
  6784. }]
  6785. };
  6786. };
  6787. var ReactiveFormsModule_1;
  6788. ReactiveFormsModule = ReactiveFormsModule_1 = __decorate([
  6789. core.NgModule({
  6790. declarations: [REACTIVE_DRIVEN_DIRECTIVES],
  6791. providers: [FormBuilder, RadioControlRegistry],
  6792. exports: [ɵInternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES]
  6793. })
  6794. ], ReactiveFormsModule);
  6795. return ReactiveFormsModule;
  6796. }());
  6797. /**
  6798. * @license
  6799. * Copyright Google Inc. All Rights Reserved.
  6800. *
  6801. * Use of this source code is governed by an MIT-style license that can be
  6802. * found in the LICENSE file at https://angular.io/license
  6803. */
  6804. /**
  6805. * @license
  6806. * Copyright Google Inc. All Rights Reserved.
  6807. *
  6808. * Use of this source code is governed by an MIT-style license that can be
  6809. * found in the LICENSE file at https://angular.io/license
  6810. */
  6811. // This file only reexports content of the `src` folder. Keep it that way.
  6812. /**
  6813. * @license
  6814. * Copyright Google Inc. All Rights Reserved.
  6815. *
  6816. * Use of this source code is governed by an MIT-style license that can be
  6817. * found in the LICENSE file at https://angular.io/license
  6818. */
  6819. /**
  6820. * Generated bundle index. Do not edit.
  6821. */
  6822. exports.ɵangular_packages_forms_forms_d = ɵInternalFormsSharedModule;
  6823. exports.ɵInternalFormsSharedModule = ɵInternalFormsSharedModule;
  6824. exports.ɵangular_packages_forms_forms_c = REACTIVE_DRIVEN_DIRECTIVES;
  6825. exports.ɵangular_packages_forms_forms_a = SHARED_FORM_DIRECTIVES;
  6826. exports.ɵangular_packages_forms_forms_b = TEMPLATE_DRIVEN_DIRECTIVES;
  6827. exports.ɵangular_packages_forms_forms_e = CHECKBOX_VALUE_ACCESSOR;
  6828. exports.ɵangular_packages_forms_forms_f = DEFAULT_VALUE_ACCESSOR;
  6829. exports.ɵangular_packages_forms_forms_g = AbstractControlStatus;
  6830. exports.ɵangular_packages_forms_forms_h = ngControlStatusHost;
  6831. exports.ɵangular_packages_forms_forms_i = formDirectiveProvider;
  6832. exports.ɵangular_packages_forms_forms_j = NG_FORM_SELECTOR_WARNING;
  6833. exports.ɵangular_packages_forms_forms_k = formControlBinding;
  6834. exports.ɵangular_packages_forms_forms_l = modelGroupProvider;
  6835. exports.ɵangular_packages_forms_forms_z = ɵNgNoValidate;
  6836. exports.ɵNgNoValidate = ɵNgNoValidate;
  6837. exports.ɵangular_packages_forms_forms_m = NUMBER_VALUE_ACCESSOR;
  6838. exports.ɵangular_packages_forms_forms_n = RADIO_VALUE_ACCESSOR;
  6839. exports.ɵangular_packages_forms_forms_o = RadioControlRegistry;
  6840. exports.ɵangular_packages_forms_forms_p = RANGE_VALUE_ACCESSOR;
  6841. exports.ɵangular_packages_forms_forms_q = NG_MODEL_WITH_FORM_CONTROL_WARNING;
  6842. exports.ɵangular_packages_forms_forms_r = formControlBinding$1;
  6843. exports.ɵangular_packages_forms_forms_s = controlNameBinding;
  6844. exports.ɵangular_packages_forms_forms_t = formDirectiveProvider$1;
  6845. exports.ɵangular_packages_forms_forms_v = formArrayNameProvider;
  6846. exports.ɵangular_packages_forms_forms_u = formGroupNameProvider;
  6847. exports.ɵangular_packages_forms_forms_w = SELECT_VALUE_ACCESSOR;
  6848. exports.ɵangular_packages_forms_forms_y = ɵNgSelectMultipleOption;
  6849. exports.ɵNgSelectMultipleOption = ɵNgSelectMultipleOption;
  6850. exports.ɵangular_packages_forms_forms_x = SELECT_MULTIPLE_VALUE_ACCESSOR;
  6851. exports.ɵangular_packages_forms_forms_bb = CHECKBOX_REQUIRED_VALIDATOR;
  6852. exports.ɵangular_packages_forms_forms_bc = EMAIL_VALIDATOR;
  6853. exports.ɵangular_packages_forms_forms_be = MAX_LENGTH_VALIDATOR;
  6854. exports.ɵangular_packages_forms_forms_bd = MIN_LENGTH_VALIDATOR;
  6855. exports.ɵangular_packages_forms_forms_bf = PATTERN_VALIDATOR;
  6856. exports.ɵangular_packages_forms_forms_ba = REQUIRED_VALIDATOR;
  6857. exports.AbstractControlDirective = AbstractControlDirective;
  6858. exports.AbstractFormGroupDirective = AbstractFormGroupDirective;
  6859. exports.CheckboxControlValueAccessor = CheckboxControlValueAccessor;
  6860. exports.ControlContainer = ControlContainer;
  6861. exports.NG_VALUE_ACCESSOR = NG_VALUE_ACCESSOR;
  6862. exports.COMPOSITION_BUFFER_MODE = COMPOSITION_BUFFER_MODE;
  6863. exports.DefaultValueAccessor = DefaultValueAccessor;
  6864. exports.NgControl = NgControl;
  6865. exports.NgControlStatus = NgControlStatus;
  6866. exports.NgControlStatusGroup = NgControlStatusGroup;
  6867. exports.NgForm = NgForm;
  6868. exports.NgFormSelectorWarning = NgFormSelectorWarning;
  6869. exports.NgModel = NgModel;
  6870. exports.NgModelGroup = NgModelGroup;
  6871. exports.NumberValueAccessor = NumberValueAccessor;
  6872. exports.RadioControlValueAccessor = RadioControlValueAccessor;
  6873. exports.RangeValueAccessor = RangeValueAccessor;
  6874. exports.FormControlDirective = FormControlDirective;
  6875. exports.FormControlName = FormControlName;
  6876. exports.FormGroupDirective = FormGroupDirective;
  6877. exports.FormArrayName = FormArrayName;
  6878. exports.FormGroupName = FormGroupName;
  6879. exports.NgSelectOption = NgSelectOption;
  6880. exports.SelectControlValueAccessor = SelectControlValueAccessor;
  6881. exports.SelectMultipleControlValueAccessor = SelectMultipleControlValueAccessor;
  6882. exports.CheckboxRequiredValidator = CheckboxRequiredValidator;
  6883. exports.EmailValidator = EmailValidator;
  6884. exports.MaxLengthValidator = MaxLengthValidator;
  6885. exports.MinLengthValidator = MinLengthValidator;
  6886. exports.PatternValidator = PatternValidator;
  6887. exports.RequiredValidator = RequiredValidator;
  6888. exports.FormBuilder = FormBuilder;
  6889. exports.AbstractControl = AbstractControl;
  6890. exports.FormArray = FormArray;
  6891. exports.FormControl = FormControl;
  6892. exports.FormGroup = FormGroup;
  6893. exports.NG_ASYNC_VALIDATORS = NG_ASYNC_VALIDATORS;
  6894. exports.NG_VALIDATORS = NG_VALIDATORS;
  6895. exports.Validators = Validators;
  6896. exports.VERSION = VERSION;
  6897. exports.FormsModule = FormsModule;
  6898. exports.ReactiveFormsModule = ReactiveFormsModule;
  6899. Object.defineProperty(exports, '__esModule', { value: true });
  6900. }));
  6901. //# sourceMappingURL=forms.umd.js.map