ãããŠãããã¯
ååãšããŠã移è¡ããã®å€§èŠæš¡ãªãããžã§ã¯ãã¯ããã®ããã»ã¹ã®äžéææ§ãšãã®ãããã¯ã«é¢ããè³æã®äžè¶³ã劚ããŸãã
å ¬åŒã¬ã€ãã§ã¯ãçºçããå¯èœæ§ã®ãããã¹ãŠã®åé¡ã®ã»ãã®äžéšãèŠã€ããããšãã§ããŸãããŸããããã°ã§ã¯ãååãšããŠããããå確èªããã ãã§ãã
ãã®èšäºã§ã¯ãæ°ããããŒãžã§ã³ãžã®ç§»è¡æã«çºçããå¯èœæ§ã®ããåé¡ã«ã€ããŠèª¬æããæãåé¡ã®ããå ŽæãåæããŸãã
æ®å¿µãªãããæçš¿ã倧ããããããããã®ããŒãã§ã¯ãã®ç§»è¡ã®é倧ãªå€æŽã«çŠç¹ãåœãŠã次ã®ããŒãã§æ©èœãšå©ç¹ã«ã€ããŠèª¬æããŸãã ãããã移è¡ã®äž»ãªå©ç¹ã¯ãäœæ¥é床ã®å€§å¹ ãªåäžãšä¿®æ£ããããã°ã®ãªã¹ãã§ãïŒçµå±ã1.2ã®ææ°ã®ä¿®æ£ã¯1幎åã®1.2.28ã§ããïŒã
ãã®æçš¿ã2ã€ã®éšåã«åããŸããã ãã®ãã¡ã®1ã€ã¯ã2ã€ã®ãããžã§ã¯ããæ°ããããŒãžã§ã³ã«å€æããå人çãªçµéšã§ãïŒãã¿ãã¬ã®äžã«é ããŸããïŒã2ã€ç®ã¯ãçºèŠãããåé¡ã®ãªã¹ãã§ãã
移è¡ã®ã¹ããŒãªãŒ
1.2ãã1.3ãžã®ç§»è¡ãå¿
èŠãšããæåã®æ¯èŒç倧ããªãããžã§ã¯ãã¯ã12,000è¡ãè¶
ããã³ãŒãïŒäž»ã«ãã£ã¬ã¯ãã£ãïŒã«ãããããããåé¡ãçºçããªãEã©ãŒãã³ã°ãã©ãããã©ãŒã ã§ããã
2çªç®ã®ãããžã§ã¯ãã§ã¯ãããŒãžã§ã³1.2.16ãã1.4.4ãžã®ç§»è¡ãå¿ èŠã§ãããªã倧ããïŒçŽç²ãªè§åºŠã®çŽ75,000è¡ïŒã補åïŒã¢ã«ãŠã³ãã£ã³ã°ïŒã®è©³çŽ°ãè€éãªé¢ä¿ãå€ãã®åœ¢æ ãé¿ããããªãåé¡ãæ瀺ããŠããŸãããã以åã®çµéšã¯åæ°ã¥ããããŸããã
移è¡ã®æåã®çµæã¯ãã³ã³ãœãŒã«ã«å€æ°ã®ãšã©ãŒãå«ãç Žæããã¢ããªã±ãŒã·ã§ã³ãååŸããããšãäºæ³ãããŠããŸããããã¢ããªã±ãŒã·ã§ã³ã¯èµ·åããåé¡ã¯ãããŸããã§ããã ããã¯éåžžã«å¥åŠã ã£ãã®ã§ãç§ã¯å ¬åŒã¬ã€ããéããŠæ ãå§ããŸãããã説æãããåé¡ã¯ã©ããåçŸãããŸããã§ããã ãžã§ããå®äºãããšå€æããã®ã§ãQAãšèªåãã¹ãã«ã¿ã¹ã¯ãå²ãåœãŠãŸããã
ãããŠç¿æ¥ãç§ã¯9åã®ãã°ãåãåããããã«9åã®ãã°ãåãåããŸããã èŠã€ãã£ããã¹ãŠã®ãšã©ãŒã®cãã¯ãã¢ããªã±ãŒã·ã§ã³ãå£ãããšã§ã¯ãªããåäœãæç¥ã§ããªãã»ã©å€æŽããããšã§ãã
ããã§ã å€æŽãã°ãšããã«èŠã€ãã£ãã³ãããå ã®è°è«ã¯ãçç±ãæ¢ããŠåãšä»²éã«ãªããŸããã
æåã®ã¹ããããšããŠããµãŒããŒåŽã®éåæãã§ãã¯ã倱æããŸãããããã¯ã¹ããŒã¿ã¹ã§ã¯ãªãããOKããªã©ã®ããã¹ãããªããã£ãã®åœ¢åŒã®åçã§æ©èœããŸããã ããã«ã€ããŠéç¥ããããã¬ãŒã¯ã®å€æŽã¯1ã€ã§ã¯ãããŸãããã察å¿ãããã°ä¿®æ£ããããŸããã
ãã³ãïŒ XHRãªã¯ãšã¹ãã§äœæ¥ã確èªããŠãã ããã ãµãŒããŒããªããžã§ã¯ããéä¿¡ãããããããŒãapplication / jsonããæã€ããªããã£ããããå Žåãåé¡ãçºçããŸãã
次ã«ããããã¢ããã«ãã¹ããããã¹ãããŒãèœã¡ã芪ã®å¹ ãæ£ãã決å®ããããã«åæ¢ããŸããã åé¡ã¯2ã€ãããŸããã ãŸããã¹ãããŒã¯ng-showã«ãããŸãã ãããã¯ã芪ã³ã³ããã衚瀺ãããåã«åæåãããããšãæå³ããŸãã 第äºã«ãã¹ãããŒã¯$ observeãä»ããŠå±æ§ã«ç¶ããŠ/ hid ã衚瀺ããŸãã ã äœããã®çç±ã§ãå€ãããŒãžã§ã³ã§ã¯ã芪ãïŒvisibleã«ãªã£ãŠããå±æ§ãå€æŽãããæ°ããå±æ§ã§ã¯ãã®éã«ãªããŸãã
ãã³ãïŒ
ãã®åé¡ã¯ã $ evalå ã®åŒã®æ¡ä»¶ã«ã圱é¿ããŸãããããã€ãã®ãããã¯ãæ¶ãå§ããŸããã ããããåé¡ã¯å¥ã®ãã°ä¿®æ£ã§ããããšãå€æãããã§ã«ããã§ã«ããŒãããŠããŸãã
ãã³ãïŒãã¬ãŒã ã¯ãŒã¯ã®ææžåãããŠããªãæ©èœã䜿çšããªãã§ãã ããã $ã¹ã³ãŒãã®æ¬¡ã®å€ããã§ãã¯ãããšãã«äœ¿çšããã³ãŒãã調ã¹ãŠãã ããïŒ 'f' ã '0' ã 'false' ã 'no' ã 'n' ã '[]' ã
çºçããäž»ãªåé¡ã¯æ€èšŒã§ãã ããŒãžã§ã³1.3ããããã©ãŒã ããã§ãã¯ããããã®æ°ããæ¹æ³ãè§åºŠããç»å Žããæ°ããèœãšãç©ŽããããŸããã ãã ããæ°ããæ€èšŒã䜿çšããäºå®ããªãå Žåã§ããåé¡ãçºçããå¯èœæ§ããããŸãã ãããã¯ã maxlength / minlengthãã£ã¬ã¯ãã£ããšããã©ãŒã ãæ°žç¶çã«ç¡å¹ã«ããæãããã$ setValidityã®æ°ããããžãã¯ã§ãïŒããã¯ç§ãã¡ã«èµ·ãã£ãããšã§ãïŒã
æ°ããããŒãžã§ã³ã§ã¯æå¹æ¡ä»¶ã®1ã€ãngModelCtrlã®ç©ºã®ããã·ã¥ã§ããããã ngModelCtrl ã
ãã³ãïŒå ¬åŒã®APIã§æå®ãããŠããªã$ã§å§ãŸãããããã£ãå ¥åããªãã§ãã ããã
ng-maxlength / ng-minlengthãã£ã¬ã¯ãã£ããšäžŠè¡ããŠãã¹ã¯ïŒé»è©±ãå¥çŽçªå·ãªã©ïŒã䜿çšããå ¥åã§å¥ã®åé¡ãçºçããŸããã
ãããã®ãã£ã¬ã¯ãã£ãã¯äž¡æ¹ãšãã ngModelCtrlã$ ModelValueã®ä»£ããã«ngModelCtrlã$ ViewValueããã§ãã¯ããŸããããã¯ãå€ "xx-xx"ã®æ倧é·ã4ã§ã¯ãªã5ïŒ "-"æåãèæ ®ïŒã§ããããšãæå³ããŸãã ã¢ããªã±ãŒã·ã§ã³å šäœã§æ°çŸã®æ€èšŒã«ãŒã«ãæžãçŽããªããã°ãªããªãã®ã§ããã¹ãŠã®ng-maxlengthãã«ã¹ã¿ã model-maxlengthã«çœ®ãæããŠãã¢ãã«ã®åãã§ãã¯ã®ã¿ãè¡ãããšã«ããŸããã ãããŠããã®æ±ºå®ã¯ã²ã©ããã®ã§ããïŒ Angularã¯maxlengthå¶éå±æ§ãèªåçšã«äºçŽããŸãããã€ãŸããå ¥åããæåæ°ãå¶éã§ããªããªããŸããã ãã®çµæããã¹ã¯ã·ã³ãã«ãèæ ®ããŠããã¹ãŠã®ã«ãŒã«ãæ°ããã«ãŒã«ã«å€æŽããããšã決å®ãããŸããã ãã ããã«ã¹ã¿ã model-minlengthãã£ã¬ã¯ãã£ãã¯ãäºåå®çŸ©ãããæåïŒããšãã°ãé»è©±ã® "+7"ïŒããããã£ã¬ã¯ãã£ãã§ã¢ããªã±ãŒã·ã§ã³ãèŠã€ããããã ngModelCtrlã$ ViewValueã§èšå®ããããã¬ãã£ãã¯ã¹ãªãã§ã¢ãã«ã®ã¿ããã§ãã¯ã§ããŸãã
ãã³ãïŒãã¹ã¯ã䜿çšããå ŽåããŸãã¯ngModelCtrlã$ ViewValueã®å€ãæäœããå Žåã¯ããã¹ã¯ã®æåã«åºã¥ããŠãã§ãã¯ãå€æŽããŸãã ng-minlengthãã§ãã¯ã䜿çšããŠå ¥åã®äºåå®çŸ©å€ã«ãã¬ãŒã¹ãã«ããŒå±æ§ã䜿çšãããããã§ãã¯ãã«ã¹ã¿ã ãã§ãã¯ã«çœ®ãæããŸãã ãã®ãããªãã£ã¬ã¯ãã£ãã®äœæ¥ã³ãŒãã¯ããã¬ãŒã¯å€æŽãªã¹ãã«ãããŸãã
åé¡ã®2çªç®ã®æ³¢ã¯ãæ€èšŒãæ°ãããã®ïŒããããªãã $ãã©ãŒããã¿ãŒ ãããã³$ããŒãµãŒ ïŒã«ç§»è¡ããåŸã«çºçããŸããã å€ãã®ãã©ãŒã ãåã³æ°žä¹ ã«ç¡å¹ã«ãªã£ããšããäºå®ã«çŽé¢ããŠããŸãã
åææ€èšŒïŒ $ validators ïŒã䜿çšãããšãåé¡ãããã«æããã«ãªããŸããã ããã¯ããã©ãŒã ã«æ€èšŒãã§ãã¯ä»ãã®ng-showã§é ããããã£ãŒã«ãããããšããäºå®ã«ãããŸããã å€ãããŒãžã§ã³ïŒ $ãã©ãŒããã¿ãŒãš$ããŒãµãŒ ïŒ ã®äœæ¥ã®æ§è³ªã«ããããããã®ãã£ãŒã«ãã¯ãã©ãŒã æ€èšŒã«å«ãŸããŠããŸããã§ããããæ°ããããŒãžã§ã³ïŒ $ããªããŒã¿ãŒ ïŒã§ã¯é衚瀺ã®ç¡å¹ãªãã£ãŒã«ãã衚瀺ãããŸãã
ãã³ãïŒé衚瀺ã®åçãã£ãŒã«ããæã€ãã©ãŒã ãããå Žåããããã®ãã£ãŒã«ããé衚瀺ã«ããã ã ng-ifã§è¡šç€ºããŸããng-show/ ng-hideã¯äœ¿çšããªãã§ãã ããã
éåææ€èšŒã¯ããå°é£ã§ããããšãå€æããŸããããã©ãŒã ã¯ç¡å¹ã§ãããããšã©ãŒã¯å«ãŸããŠããŸããã§ããã
ããã§ã¯ããã¹ã¯ã®æ©èœã«ããïŒ $ formattersããã³$ parsersãä»ããŠïŒãåææ€èšŒãå®äºããåã«éåææ€èšŒãåŒã³åºããã1ã€ã®å€æŽãããæåã«å¯ŸããŠæ°ååŒã³åºãããŸããã ããã«ãããè€æ°ã®çŽæã®äœæãã°ãçºçããæåŸã®çŽæã解決ãŸãã¯æåŠãããªãã£ããšããäºå®ã«è³ããŸããã ãããã£ãŠãå ¥åã¯ç¡æéã«ä¿çããããã©ãŒã ã¯ãšã©ãŒãªãã§ç¡å¹ã«ãªããŸããã
ãã³ãïŒéåæããªããŒã¿ãŒã®åäœããã¹ãããŸããè¿ããããããã¹ãåžžã«è§£æ±ºãŸãã¯æåŠãããããšã確èªããŸãã
æ€èšŒã®æãå¥åŠãªåé¡ã¯ãéé¡ãå ¥åããããã®ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã§ããïŒã«ãŒãã«ãšã»ã³ãã®2ã€ã®å ¥åã®ããã«èŠããngModelã«ãããã®æ°å€ãé£çµããæ¢è£œã®çµæãäžããŸãïŒã 圌女ã¯ç¡å¹ã§ããã ãã§ãªãããã¬ãŒã ã¯ãŒã¯ã®å¥¥ããã³ã³ãœãŒã«ã«ãšã©ãŒãäŒããŸããã
åé¡ã«è²»ããããæéã¯ããªãè¯ãã£ããåé¡ã¯åã³ng-maxlengthã§ããã解決çã¯ç°¡åã ã£ãïŒ$ formatValuesãã£ã¬ã¯ãã£ãã®æååã«$ viewValueå€ãè¿œå ããŸããã
ãããããªãåé¡ãçºçããã®ã§ããããïŒ ãããç解ããŸãããïŒ
ããã¯ãã¹ãŠ$ã³ã³ãã€ã«ã®äœæ¥ã«é¢ãããã®ã§ããã¡ã€ã³ãã£ã¬ã¯ãã£ãã®åäœã¯å éšã«èšè¿°ãããŠããŸãã ããšãã°ã inputããã³textareaã®å Žåã inputDirectiveã³ã³ãããŒã«ãåŒã³åºãããŸã ãããã¯attr.typeãåãåããããã«åºã¥ããŠinputTypeã³ã¬ã¯ã·ã§ã³ã®é¢æ°ã®1ã€ãåŒã³åºããŸãã ããã¹ãã¿ã€ãã®å Žåãããã¯textInputTypeã§ãã 次ã«ã圌ã¯ã³ã³ãããŒã«ãstringBasedInputTypeé¢æ°ã«ã¹ããŒããŸãããã®é¢æ°ã¯ãå€ã$ formattersã®æååã«å€æããããã®ã³ãŒããè¿œå ããŸãã
ãããã£ãŠã ngModelã inputãªã©ã®æ¢åã®åºæ¬èŠçŽ ã«é¢é£ä»ããããŠããªãããããšãã°åçŽãªæ姫ãŸãã¯ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãïŒãã®å Žåãéé¡ãå ¥åããããã®ãã£ã¬ã¯ãã£ãïŒã§ãã³ã°ããŠããå ŽåãããŒã¿ã¯ã ãã®ãŸãŸ ã $ viewModelã«ããŒã«ãããŸããããã«ãããmaxlengthãªã©ã®ãã£ã«ã¿ãŒãã£ã¬ã¯ãã£ãã§ãšã©ãŒãçºçããŸããmaxlengthã¯ãæ°å€ã«ãªã.lengthããããã£ã䜿çšããŸãã
Plunkerã®å®äŸ ã
ãã³ãïŒæ°å€ã§æ©èœãããã¹ãŠã®ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã«ã¯ãæ°å€ãæååã«å€æããããã®é©åãªãã©ãŒããã¿ãŒãå¿ èŠã§ãã
ãã®çµæããã¹ãã®çŽ6åã®å埩ãå®è¡ããã54ã®åé¡ãèŠã€ãããŸãããããããã®ã»ãšãã©ã¯åæ§ã®æ§è³ªãåããŠããŸããã åé¡ã®äžéšããŸã£ãããªãã£ãå¯èœæ§ããããŸããäœæ¥ã®ãã°ãææžåãããŠããªãæ©èœã®ããã«äžéšã®ã³ãŒãã»ã¯ã·ã§ã³ã䜿çšããªãã§ãã ããã ãªãã¡ã¯ã¿ãªã³ã°ãšæ°ããæ€èšŒãžã®åãæ¿ããèæ ®ããŠãåèš56ã®ã³ããããš1人ããã3é±éã®äœæ¥æéã移è¡ã«è²»ããããŸããã
2çªç®ã®ãããžã§ã¯ãã§ã¯ãããŒãžã§ã³1.2.16ãã1.4.4ãžã®ç§»è¡ãå¿ èŠã§ãããªã倧ããïŒçŽç²ãªè§åºŠã®çŽ75,000è¡ïŒã補åïŒã¢ã«ãŠã³ãã£ã³ã°ïŒã®è©³çŽ°ãè€éãªé¢ä¿ãå€ãã®åœ¢æ ãé¿ããããªãåé¡ãæ瀺ããŠããŸãããã以åã®çµéšã¯åæ°ã¥ããããŸããã
移è¡ã®æåã®çµæã¯ãã³ã³ãœãŒã«ã«å€æ°ã®ãšã©ãŒãå«ãç Žæããã¢ããªã±ãŒã·ã§ã³ãååŸããããšãäºæ³ãããŠããŸããããã¢ããªã±ãŒã·ã§ã³ã¯èµ·åããåé¡ã¯ãããŸããã§ããã ããã¯éåžžã«å¥åŠã ã£ãã®ã§ãç§ã¯å ¬åŒã¬ã€ããéããŠæ ãå§ããŸãããã説æãããåé¡ã¯ã©ããåçŸãããŸããã§ããã ãžã§ããå®äºãããšå€æããã®ã§ãQAãšèªåãã¹ãã«ã¿ã¹ã¯ãå²ãåœãŠãŸããã
ãããŠç¿æ¥ãç§ã¯9åã®ãã°ãåãåããããã«9åã®ãã°ãåãåããŸããã èŠã€ãã£ããã¹ãŠã®ãšã©ãŒã®cãã¯ãã¢ããªã±ãŒã·ã§ã³ãå£ãããšã§ã¯ãªããåäœãæç¥ã§ããªãã»ã©å€æŽããããšã§ãã
ããã§ã å€æŽãã°ãšããã«èŠã€ãã£ãã³ãããå ã®è°è«ã¯ãçç±ãæ¢ããŠåãšä»²éã«ãªããŸããã
æåã®ã¹ããããšããŠããµãŒããŒåŽã®éåæãã§ãã¯ã倱æããŸãããããã¯ã¹ããŒã¿ã¹ã§ã¯ãªãããOKããªã©ã®ããã¹ãããªããã£ãã®åœ¢åŒã®åçã§æ©èœããŸããã ããã«ã€ããŠéç¥ããããã¬ãŒã¯ã®å€æŽã¯1ã€ã§ã¯ãããŸãããã察å¿ãããã°ä¿®æ£ããããŸããã
ãã³ãïŒ XHRãªã¯ãšã¹ãã§äœæ¥ã確èªããŠãã ããã ãµãŒããŒããªããžã§ã¯ããéä¿¡ãããããããŒãapplication / jsonããæã€ããªããã£ããããå Žåãåé¡ãçºçããŸãã
次ã«ããããã¢ããã«ãã¹ããããã¹ãããŒãèœã¡ã芪ã®å¹ ãæ£ãã決å®ããããã«åæ¢ããŸããã åé¡ã¯2ã€ãããŸããã ãŸããã¹ãããŒã¯ng-showã«ãããŸãã ãããã¯ã芪ã³ã³ããã衚瀺ãããåã«åæåãããããšãæå³ããŸãã 第äºã«ãã¹ãããŒã¯$ observeãä»ããŠå±æ§ã«ç¶ããŠ/ hid ã衚瀺ããŸãã ã äœããã®çç±ã§ãå€ãããŒãžã§ã³ã§ã¯ã芪ãïŒvisibleã«ãªã£ãŠããå±æ§ãå€æŽãããæ°ããå±æ§ã§ã¯ãã®éã«ãªããŸãã
ãã³ãïŒ
- ng-show / ng-hideã§åæåããéã«éèŠãªåçãã£ã¬ã¯ãã£ããä¿åããªãã§ãã ãããããã«ã¯ng-ifã䜿çšããŠãã ããã ãã®ãã³ãã¯ããŒãžã§ã³1.2ã§ãæå¹ã§ãã
- ä»ã®ããŒã¿ïŒDOMãŸãã¯$ã¹ã³ãŒãïŒãžã®å€éšã®å€æŽãç£èŠããå Žåã¯ã $ observeã䜿çšããŠå±æ§ã远跡ããªãã§ãã ããã ããã«ã¯$ watchïŒfunctionïŒïŒ{}ãfunctionïŒïŒ{}ïŒã䜿çšããŸãã ããã«ãã©ã¡ãã®ãªãã·ã§ã³ããŠã©ãŒã¿ãŒããŒã¯ãããŒãã£ãã§ãã¯ã«è¿œå ããŸãããå¯äžã®éãã¯ã³ãŒã«ããã¯åŒã³åºãæ¡ä»¶ã§ãã
ãã®åé¡ã¯ã $ evalå ã®åŒã®æ¡ä»¶ã«ã圱é¿ããŸãããããã€ãã®ãããã¯ãæ¶ãå§ããŸããã ããããåé¡ã¯å¥ã®ãã°ä¿®æ£ã§ããããšãå€æãããã§ã«ããã§ã«ããŒãããŠããŸãã
ãã³ãïŒãã¬ãŒã ã¯ãŒã¯ã®ææžåãããŠããªãæ©èœã䜿çšããªãã§ãã ããã $ã¹ã³ãŒãã®æ¬¡ã®å€ããã§ãã¯ãããšãã«äœ¿çšããã³ãŒãã調ã¹ãŠãã ããïŒ 'f' ã '0' ã 'false' ã 'no' ã 'n' ã '[]' ã
çºçããäž»ãªåé¡ã¯æ€èšŒã§ãã ããŒãžã§ã³1.3ããããã©ãŒã ããã§ãã¯ããããã®æ°ããæ¹æ³ãè§åºŠããç»å Žããæ°ããèœãšãç©ŽããããŸããã ãã ããæ°ããæ€èšŒã䜿çšããäºå®ããªãå Žåã§ããåé¡ãçºçããå¯èœæ§ããããŸãã ãããã¯ã maxlength / minlengthãã£ã¬ã¯ãã£ããšããã©ãŒã ãæ°žç¶çã«ç¡å¹ã«ããæãããã$ setValidityã®æ°ããããžãã¯ã§ãïŒããã¯ç§ãã¡ã«èµ·ãã£ãããšã§ãïŒã
æ°ããããŒãžã§ã³ã§ã¯æå¹æ¡ä»¶ã®1ã€ãngModelCtrlã®ç©ºã®ããã·ã¥ã§ããããã ngModelCtrl ã
ãã³ãïŒå ¬åŒã®APIã§æå®ãããŠããªã$ã§å§ãŸãããããã£ãå ¥åããªãã§ãã ããã
ng-maxlength / ng-minlengthãã£ã¬ã¯ãã£ããšäžŠè¡ããŠãã¹ã¯ïŒé»è©±ãå¥çŽçªå·ãªã©ïŒã䜿çšããå ¥åã§å¥ã®åé¡ãçºçããŸããã
ãããã®ãã£ã¬ã¯ãã£ãã¯äž¡æ¹ãšãã ngModelCtrlã$ ModelValueã®ä»£ããã«ngModelCtrlã$ ViewValueããã§ãã¯ããŸããããã¯ãå€ "xx-xx"ã®æ倧é·ã4ã§ã¯ãªã5ïŒ "-"æåãèæ ®ïŒã§ããããšãæå³ããŸãã ã¢ããªã±ãŒã·ã§ã³å šäœã§æ°çŸã®æ€èšŒã«ãŒã«ãæžãçŽããªããã°ãªããªãã®ã§ããã¹ãŠã®ng-maxlengthãã«ã¹ã¿ã model-maxlengthã«çœ®ãæããŠãã¢ãã«ã®åãã§ãã¯ã®ã¿ãè¡ãããšã«ããŸããã ãããŠããã®æ±ºå®ã¯ã²ã©ããã®ã§ããïŒ Angularã¯maxlengthå¶éå±æ§ãèªåçšã«äºçŽããŸãããã€ãŸããå ¥åããæåæ°ãå¶éã§ããªããªããŸããã ãã®çµæããã¹ã¯ã·ã³ãã«ãèæ ®ããŠããã¹ãŠã®ã«ãŒã«ãæ°ããã«ãŒã«ã«å€æŽããããšã決å®ãããŸããã ãã ããã«ã¹ã¿ã model-minlengthãã£ã¬ã¯ãã£ãã¯ãäºåå®çŸ©ãããæåïŒããšãã°ãé»è©±ã® "+7"ïŒããããã£ã¬ã¯ãã£ãã§ã¢ããªã±ãŒã·ã§ã³ãèŠã€ããããã ngModelCtrlã$ ViewValueã§èšå®ããããã¬ãã£ãã¯ã¹ãªãã§ã¢ãã«ã®ã¿ããã§ãã¯ã§ããŸãã
ãã³ãïŒãã¹ã¯ã䜿çšããå ŽåããŸãã¯ngModelCtrlã$ ViewValueã®å€ãæäœããå Žåã¯ããã¹ã¯ã®æåã«åºã¥ããŠãã§ãã¯ãå€æŽããŸãã ng-minlengthãã§ãã¯ã䜿çšããŠå ¥åã®äºåå®çŸ©å€ã«ãã¬ãŒã¹ãã«ããŒå±æ§ã䜿çšãããããã§ãã¯ãã«ã¹ã¿ã ãã§ãã¯ã«çœ®ãæããŸãã ãã®ãããªãã£ã¬ã¯ãã£ãã®äœæ¥ã³ãŒãã¯ããã¬ãŒã¯å€æŽãªã¹ãã«ãããŸãã
åé¡ã®2çªç®ã®æ³¢ã¯ãæ€èšŒãæ°ãããã®ïŒããããªãã $ãã©ãŒããã¿ãŒ ãããã³$ããŒãµãŒ ïŒã«ç§»è¡ããåŸã«çºçããŸããã å€ãã®ãã©ãŒã ãåã³æ°žä¹ ã«ç¡å¹ã«ãªã£ããšããäºå®ã«çŽé¢ããŠããŸãã
åææ€èšŒïŒ $ validators ïŒã䜿çšãããšãåé¡ãããã«æããã«ãªããŸããã ããã¯ããã©ãŒã ã«æ€èšŒãã§ãã¯ä»ãã®ng-showã§é ããããã£ãŒã«ãããããšããäºå®ã«ãããŸããã å€ãããŒãžã§ã³ïŒ $ãã©ãŒããã¿ãŒãš$ããŒãµãŒ ïŒ ã®äœæ¥ã®æ§è³ªã«ããããããã®ãã£ãŒã«ãã¯ãã©ãŒã æ€èšŒã«å«ãŸããŠããŸããã§ããããæ°ããããŒãžã§ã³ïŒ $ããªããŒã¿ãŒ ïŒã§ã¯é衚瀺ã®ç¡å¹ãªãã£ãŒã«ãã衚瀺ãããŸãã
ãã³ãïŒé衚瀺ã®åçãã£ãŒã«ããæã€ãã©ãŒã ãããå Žåããããã®ãã£ãŒã«ããé衚瀺ã«ããã ã ng-ifã§è¡šç€ºããŸããng-show/ ng-hideã¯äœ¿çšããªãã§ãã ããã
åèïŒéåæããªããŒã¿ãŒã®ä»çµã¿
éåæããªããŒã¿ãŒã¯ngModelCtrlã$ AsyncValidatorsã³ã¬ã¯ã·ã§ã³ã«ä¿åããã Promiseãè¿ãé¢æ°ã§ãã Promiseã¯ããŸããŸãªãµãŒãã¹ïŒããšãã°ã$ timeoutã$ httpïŒãè¿ããç¹å¥ãªãµãŒãã¹$ qã«ãã£ãŠãçæãããŸãã ãã£ãŒã«ãã®æå¹æ§ã¯ãè¿ããããããã¹ã®è§£æ±ºãŸãã¯æåŠã«äŸåããŸãã éåææ€èšŒã¯ããã¹ãŠã®åææ€èšŒãæå¹ã«ãªã£ãåŸã«ã®ã¿éå§ãããŸãã ããªããŒã¿ãŒãåŒã³åºããããšãããã®åŠ¥åœæ§ïŒ $ setValidity ïŒã¯æªå®çŸ©ã«ãªããæåŸ
ãããããªããŒã¿ãŒã®ååãngModelCtrlã$ Pendingã«è¡šç€ºãããŸãã promiseã®è§£æ±ºãçºçãããšããã«ããã®æå¹æ§ã¯nullã«èšå®ãããŸã ã
æ€èšŒé¢æ°ãæ°ååŒã³åºããšãæåŸã®çŽæã¯åã®ãã®ãæ¶å»ããŸãã ã€ãŸãããã£ãŒã«ãã2åæ€èšŒãããæåã®ãããã¹ã解決ããã2çªç®ã®ãããã¹ãæåŠãããå Žåããã£ãŒã«ãã¯ç¡å¹ã«ãªããŸãã
APIããã¥ã¡ã³ãã®äŸïŒ
æ€èšŒé¢æ°ãæ°ååŒã³åºããšãæåŸã®çŽæã¯åã®ãã®ãæ¶å»ããŸãã ã€ãŸãããã£ãŒã«ãã2åæ€èšŒãããæåã®ãããã¹ã解決ããã2çªç®ã®ãããã¹ãæåŠãããå Žåããã£ãŒã«ãã¯ç¡å¹ã«ãªããŸãã
APIããã¥ã¡ã³ãã®äŸïŒ
ngModel.$asyncValidators.uniqueUsername = function(modelValue, viewValue) { var value = modelValue || viewValue; // Lookup user by username return $http.get('/api/users/' + value). then(function resolved() { //username exists, this means validation fails return $q.reject('exists'); }, function rejected() { //username does not exist, therefore this validation passes return true; }); };
éåææ€èšŒã¯ããå°é£ã§ããããšãå€æããŸããããã©ãŒã ã¯ç¡å¹ã§ãããããšã©ãŒã¯å«ãŸããŠããŸããã§ããã
ããã§ã¯ããã¹ã¯ã®æ©èœã«ããïŒ $ formattersããã³$ parsersãä»ããŠïŒãåææ€èšŒãå®äºããåã«éåææ€èšŒãåŒã³åºããã1ã€ã®å€æŽãããæåã«å¯ŸããŠæ°ååŒã³åºãããŸããã ããã«ãããè€æ°ã®çŽæã®äœæãã°ãçºçããæåŸã®çŽæã解決ãŸãã¯æåŠãããªãã£ããšããäºå®ã«è³ããŸããã ãããã£ãŠãå ¥åã¯ç¡æéã«ä¿çããããã©ãŒã ã¯ãšã©ãŒãªãã§ç¡å¹ã«ãªããŸããã
ãã®ãããªå Žåã®ããªããŒã¿ãŒãæ§ç¯ããäŸ
var pendingPromise; ngModelCtrl.$asyncValidators.checkPhoneUnique = function (modelValue) { if (pendingPromise) { return pendingPromise; } var deferred = $q.defer(); if (modelValue) { pendingPromise = deferred.promise; $http.post('/', {value: modelValue}) .success(function (response) { if (response.Result === ' ') { deferred.resolve(); } else { deferred.reject(); } }).error(function () { deferred.reject(); }).finally(function () { pendingPromise = null; }); } else { deferred.resolve(); } return deferred.promise; };
ãã³ãïŒéåæããªããŒã¿ãŒã®åäœããã¹ãããŸããè¿ããããããã¹ãåžžã«è§£æ±ºãŸãã¯æåŠãããããšã確èªããŸãã
æ€èšŒã®æãå¥åŠãªåé¡ã¯ãéé¡ãå ¥åããããã®ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã§ããïŒã«ãŒãã«ãšã»ã³ãã®2ã€ã®å ¥åã®ããã«èŠããngModelã«ãããã®æ°å€ãé£çµããæ¢è£œã®çµæãäžããŸãïŒã 圌女ã¯ç¡å¹ã§ããã ãã§ãªãããã¬ãŒã ã¯ãŒã¯ã®å¥¥ããã³ã³ãœãŒã«ã«ãšã©ãŒãäŒããŸããã
åé¡ã«è²»ããããæéã¯ããªãè¯ãã£ããåé¡ã¯åã³ng-maxlengthã§ããã解決çã¯ç°¡åã ã£ãïŒ$ formatValuesãã£ã¬ã¯ãã£ãã®æååã«$ viewValueå€ãè¿œå ããŸããã
ãããããªãåé¡ãçºçããã®ã§ããããïŒ ãããç解ããŸãããïŒ
ããã¯ãã¹ãŠ$ã³ã³ãã€ã«ã®äœæ¥ã«é¢ãããã®ã§ããã¡ã€ã³ãã£ã¬ã¯ãã£ãã®åäœã¯å éšã«èšè¿°ãããŠããŸãã ããšãã°ã inputããã³textareaã®å Žåã inputDirectiveã³ã³ãããŒã«ãåŒã³åºãããŸã ãããã¯attr.typeãåãåããããã«åºã¥ããŠinputTypeã³ã¬ã¯ã·ã§ã³ã®é¢æ°ã®1ã€ãåŒã³åºããŸãã ããã¹ãã¿ã€ãã®å Žåãããã¯textInputTypeã§ãã 次ã«ã圌ã¯ã³ã³ãããŒã«ãstringBasedInputTypeé¢æ°ã«ã¹ããŒããŸãããã®é¢æ°ã¯ãå€ã$ formattersã®æååã«å€æããããã®ã³ãŒããè¿œå ããŸãã
ãããã£ãŠã ngModelã inputãªã©ã®æ¢åã®åºæ¬èŠçŽ ã«é¢é£ä»ããããŠããªãããããšãã°åçŽãªæ姫ãŸãã¯ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãïŒãã®å Žåãéé¡ãå ¥åããããã®ãã£ã¬ã¯ãã£ãïŒã§ãã³ã°ããŠããå ŽåãããŒã¿ã¯ã ãã®ãŸãŸ ã $ viewModelã«ããŒã«ãããŸããããã«ãããmaxlengthãªã©ã®ãã£ã«ã¿ãŒãã£ã¬ã¯ãã£ãã§ãšã©ãŒãçºçããŸããmaxlengthã¯ãæ°å€ã«ãªã.lengthããããã£ã䜿çšããŸãã
Plunkerã®å®äŸ ã
ãã³ãïŒæ°å€ã§æ©èœãããã¹ãŠã®ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã«ã¯ãæ°å€ãæååã«å€æããããã®é©åãªãã©ãŒããã¿ãŒãå¿ èŠã§ãã
çµæïŒ
ãã®çµæããã¹ãã®çŽ6åã®å埩ãå®è¡ããã54ã®åé¡ãèŠã€ãããŸãããããããã®ã»ãšãã©ã¯åæ§ã®æ§è³ªãåããŠããŸããã åé¡ã®äžéšããŸã£ãããªãã£ãå¯èœæ§ããããŸããäœæ¥ã®ãã°ãææžåãããŠããªãæ©èœã®ããã«äžéšã®ã³ãŒãã»ã¯ã·ã§ã³ã䜿çšããªãã§ãã ããã ãªãã¡ã¯ã¿ãªã³ã°ãšæ°ããæ€èšŒãžã®åãæ¿ããèæ ®ããŠãåèš56ã®ã³ããããš1人ããã3é±éã®äœæ¥æéã移è¡ã«è²»ããããŸããã
ããŒã1ïŒé倧ãªå€æŽ
ç§ã¯ããã«IE8ã®ãµããŒãã倱ãã€ã€ããããšã«æ³šæããŸãã ãã ããå¿ èŠãªããªãã£ã«ãæ¥ç¶ããããšã§è¿ãããšãã§ããŸãã
Work $ parse
.bindã.callã.apply
åŒïŒããšãã°{{}} ïŒå ã§.bind ã .callãããã³.applyãåŒã³åºãããšã¯ã§ããªããªããŸããã
ããã«ãããæ¢åã®é¢æ°ã®åäœãå€æŽã§ããªãããšã確èªã§ããŸãã
__proto__
ããŒãžã§ã³1.3ããã éæšå¥šã® __proto__ããããã£ãåé€ãããŸããã
以åã¯ãã°ããŒãã«ãããã¿ã€ãã«ã¢ã¯ã»ã¹ããããã«äœ¿çšã§ããŸããã
察象
åŒå ã§ãªããžã§ã¯ãã䜿çšããããšã¯çŠæ¢ãããŠããŸãã
ããã¯ãåŒã§ä»»æã®ã³ãŒããå®è¡ã§ããããã§ãã
äŸïŒ
''.sub.call.call( ({})["constructor"].getOwnPropertyDescriptor(''.sub.__proto__, "constructor").value, null, "alert('evil')" )()
誰ããObject.keyãŸãã¯å¥ã®ã¡ãœãããå¿ èŠãšããå Žåã scopeãä»ããŠã¹ããŒããŸã ã
{å®çŸ©ãã«ãã¯ã¢ãã} {ã²ãã¿ãŒãã»ãã¿ãŒ}
ããŒãžã§ã³1.3以éã {defineãlookup} {GetterãSetter}ããããã£ã¯çŠæ¢ãããŠãããåŒå ã§ä»»æã®ã³ãŒããå®è¡ã§ããŸãã
ãããã®ããããã£ãå¿ èŠãªå Žåã¯ãããããã³ã³ãããŒã©ã§ã©ããããæã§ã¹ã³ãŒãã«ããŒã«ããŸãã
$ parseProvider
[ã³ããã]å»æ¢ããã$ parseProvider.unwrapPromisesããã³$ parseProvider.logPromiseWarningsã¡ãœãããåé€ããŸããã
$è£éãã
$ interpolateã«ãã£ãŠè¿ãããé¢æ°ã«ã¯ã .partsé åãå«ãŸããªããªããŸããã 代ããã«ã以äžãå«ãŸããŸã
- .expressions ãããã¹ãå
ã®ãã¹ãŠã®åŒãå«ãŸããŸãã
- .separators ãããã¹ãå
ã®åŒã®éã«ã»ãã¬ãŒã¿ããããŸãã çµåã®äŸ¿å®äžãåžžã«.expressionsããã1èŠçŽ é·ããªããŸãã
toBoolean
æ ŒçŽåº«ã§ã¯ãçå®ã確èªããããã«ãç¬èªã®toBooleanïŒïŒã®å®è£ ã䜿çšããŸããããã¯ã次ã®è¡ã®åœ¢åŒã§ããã€ãã®éæšæºå€ãfalseãšåçã«ããŸã ã
'f' ã '0' ã 'false' ã 'no' ã 'n' ã '[]'
ããŒãžã§ã³1.3以éãéåžžã®JSãšåãå€ã®ã¿ãfalseã«èšå®ãããŸãã
false ã null ã undefined ã NaN ã 0 ã ãã
habrã§ããã«ã€ããŠæžãã
äŸïŒ
<1.3ïŒ
1.3+ïŒ
$scope.isEnabled = 'no';
<1.3ïŒ
{{ isEnabled ? ' ' : '' }}
1.3+ïŒ
{{ isEnabled ? '' : ' ' }}
ãã«ããŒ
.copyïŒïŒ
以åã¯ããªããžã§ã¯ããæäœãããšãã ã³ããŒã¯ããããã¿ã€ãã«ãããã®ãå«ããªããžã§ã¯ãã®ãã¹ãŠã®ããããã£ãã³ããŒãããããã¿ã€ããã§ãŒã³ïŒDateãRegExpãããã³Arrayãé€ãïŒã倱ãããŸããã
ããŒãžã§ã³1.3以éãç¬èªã®ããããã£ïŒ hasOwnPropertyã«ãããœãŒãã®ãããªãã®ïŒã®ã¿ãã³ããŒããå ã®ãããã¿ã€ããåç §ããŸãã
äŸïŒ
<1.3ïŒ
1.3+ïŒ
IE8ïŒ Polyfill Object.createããã³Object.getPrototypeOfãå¿ èŠ
var Foo = function() {}; Foo.prototype.bar = 1; var foo = new Foo(); var fooCopy = angular.copy(foo); foo.bar = 3;
<1.3ïŒ
console.log(foo instanceof Foo); // => true console.log(fooCopy instanceof Foo); // => false console.log(foo.bar); // => 3 console.log(fooCopy.bar); // => 1
1.3+ïŒ
console.log(foo instanceof Foo); // => true console.log(fooCopy instanceof Foo); // => true console.log(foo.bar); // => 3 console.log(fooCopy.bar); // => 3
IE8ïŒ Polyfill Object.createããã³Object.getPrototypeOfãå¿ èŠ
.forEachïŒïŒ
以åã¯ãåæã®éçšã§é åãå¢å ããå Žåããµã€ã¯ã«ã¯æ°ããåºçŸããèŠçŽ ãééããŸããã
ããŒãžã§ã³1.3以éãé åå ã®èŠçŽ ã®æ°ããã£ãã·ã¥ãããããã«æ²¿ã£ãŠã®ã¿æž¡ããŸããããã§ã¯ããã€ãã£ãã®Array.forEachã«è¿ã¥ããŸãã ã
äŸïŒ
<1.3ïŒ
1.3+ïŒ
var foo = [1, 2];
<1.3ïŒ
angular.forEach(foo, function (value, key) { foo.push(null); // => null console.log(value); });
1.3+ïŒ
angular.forEach(foo, function(value, key) { foo.push(null); // => 1, 2 console.log(value); });
.toJsonïŒïŒ
ãã®ãã«ããŒã®æ¬è³ªã¯ãäž»ã«ãã¹ãŠã®ããŒã¿ãã·ãªã¢ã«åããã®ã§ã¯ãªããç¹æ®æå$ã§å§ãŸããªãããŒã¿ã®ã¿ãã·ãªã¢ã«åããããšã§ãã
ããŒãžã§ã³1.3以éãååã$$ã§å§ãŸãããããã£ã®ã¿ãã·ãªã¢ã«åããŸããã
äŸïŒ
<1.3ïŒ
1.3+ïŒ
var foo = {bar: 1, baz: 2, $qux: 3};
<1.3ïŒ
angular.toJson(value); // => {"bar": 1}
1.3+ïŒ
angular.toJson(value); // => {"bar": 1, "$bar": 2}
jqLitââe
äž»ãªãã®ã«ã€ããŠç°¡åã«ïŒ
- ããŒã¿ãããã¹ãããã³ã³ã¡ã³ãããŒãã«èšå®ã§ããªããªããŸãã ããã¯ãã¡ã¢ãªãªãŒã¯ãšæµåhemoã«ãããã®ã§ãã
- element.detachïŒïŒãåŒã³åºããŠãã$ destroyã€ãã³ãã¯ããªã¬ãŒãããŸããã
éžæããŠãã ãã
ã³ã³ãããŒã©ãŒ
SelectController㯠ã Selectãã£ã¬ã¯ãã£ããšngOptionsãã£ã¬ã¯ãã£ãã®æœè±¡åã®1ã€ã§ãã
ããã¯ã ngOptionsãSelectããåé€ã§ããããã«ãªã£ãããšãæå³ããŸãã
Selectãã£ã¬ã¯ãã£ãã®ããŸããŸãªããªãšãŒã·ã§ã³ã«ã¯ãç¬èªã®ã¡ãœããSelectController.writeValueããã³SelectController.readValueããã ããããã¯$ viewValueã¿ã°<select>ããã³ãã®å<option>ã®æäœãæ åœããŸãã
ngOptionsã®å€
以åã®ngOptionsã§ã¯ã代çããŒã¯è»¢éãããã³ã¬ã¯ã·ã§ã³ã®ã€ã³ããã¯ã¹ãŸãã¯ã¢ã€ãã ããŒã䜿çšããŠããŸããã
ããŒãžã§ã³1.4以éãã³ã¬ã¯ã·ã§ã³å ã®ãã®ã¢ã€ãã ã«å¯ŸããŠhashKeyåŒã³åºãã䜿çšãããŸãã
ãããã£ãŠã DOMããå€ãçŽæ¥èªã¿åããšãåé¡ãçºçããå¯èœæ§ããããŸãã
äŸïŒ
<1.4ïŒ
1.4以éïŒ
<select ng-model="model" ng-option="i in items"></select>
<1.4ïŒ
<option value="1">a</option> <option value="2">b</option> <option value="3">c</option> <option value="4">d</option>
1.4以éïŒ
<option value="string:a">a</option> <option value="string:b">b</option> <option value="string:c">c</option> <option value="string:d">d</option>
ngModelãšãªãã·ã§ã³å€ã®æ¯èŒ
ããŒãžã§ã³1.4以éã selectãã£ã¬ã¯ãã£ãã¯ãå³å¯ãªæ¯èŒã䜿çšããŠoptionãšngModelã®å€ã®æ¯èŒãéå§ããŸã ã
ããã¯ãå€1ã falseãŸãã¯trueã®å€ãšåçã§ã¯ãªãã®ãšåãããã«ãå€1ãã1ããšåçã§ã¯ãªãããšãæå³ããŸã ã
ã¢ãã«ã«å€1ãå ¥åãããšã äžæãªãªãã·ã§ã³ã衚瀺ãããŸã ã
ãããåé¿ããã«ã¯ãã¢ãã«ã«scope.model = "1"ãªã©ã®æååãé 眮ããå¿ èŠããããŸãã
ã¢ãã«ã«æ£ç¢ºãªæ°å€ãå¿ èŠãªå Žåã¯ããã©ãŒããã¿ãŒãšããŒãµãŒã䜿çšããå€æã䜿çšããããšããå§ãããŸãã
äŸïŒ
ngModelCtrl.$parsers.push(function(value) { return parseInt(value, 10); // }); ngModelCtrl.$formatters.push(function(value) { return value.toString(); // });
ä»åã
ngRepeatã®å Žåã®ããã« ãã¢ã«ãã¡ãããé ã®ãœãŒãã¯æ©èœããªããªããŸãããã Object.keysïŒobjïŒã®åŒã³åºãã«é çªã«å¯Ÿå¿ããŠããŸãã
ngRepeat
ä»åã
[ã³ããã] [åé¡] [èæŠ]以åã¯ãngRepeatã¯ããªããžã§ã¯ãããœãŒãããããŒã§ã¢ã«ãã¡ãããé ã«ãœãŒãããŠããŸããã ããŒãžã§ã³1.4ããã¯ãããããobjã®ããŒãå埩åŠçããŠãããã®ããã«ããã©ãŠã¶åºæã®é åºã§ãããè¿ããŸãã
ããã¯ãããŒãåé€ãŸãã¯åã€ã³ã¹ããŒã«ãããªãéã ãéåžžããã©ãŠã¶ã宣èšãããé åºã§ãªããžã§ã¯ãã®ããŒãè¿ãããã§ãã
ãªããžã§ã¯ããå埩åŠçããã«ã¯ããªããžã§ã¯ããé åã«å€æããã«ã¹ã¿ã ãã£ã«ã¿ãŒã䜿çšããããšããå§ãããŸãã
$ã³ã³ãã€ã«
controllerAsãbindToController
ããŒãžã§ã³1.3ã§ã¯ã bindToControllerãå°å ¥ãããŸããã ããŒãžã§ã³1.4以éããªããžã§ã¯ããæž¡ããŠãåé¢ãããã¹ã³ãŒããæå®ã§ããŸãã
ãã®ç¹ã§ãã³ã³ãããŒã©ãŒã³ã³ã¹ãã©ã¯ã¿ãŒããè¿ããããªããžã§ã¯ãã¯ã¹ã³ãŒããäžæžãããŸãã
controllerAsæ§æã䜿çšãããã¥ãŒã¯ãé¢æ°èªäœãžã®åç §ãåãåãããé¢æ°ãè¿ããªããžã§ã¯ããžã®åç §ãåãåããŸãã
bindToControllerããã£ã¬ã¯ãã£ãã§äœ¿çšãããŠããå Žåã以åã®ãã¹ãŠã®ãã€ã³ãã£ã³ã°ãæ°ããã³ã³ãããŒã©ãŒã«åã€ã³ã¹ããŒã«ãããã€ã³ã¹ããŒã«ãããŠãããã¹ãŠã®ãŠã©ããã£ãŒãåé€ãããŸãïŒ unwatch ïŒã
å€ç«ããã¹ã³ãŒãå ã®åŒãïŒã
以åã¯ãåŒãæã€å±æ§ãååšããªãå Žåã§ããé¢æ°ã¯åžžã«åŒïŒã§äœæãããŠããŸããïŒãã®å Žåã undefinedãè¿ãé¢æ°ãäœæãããŸããïŒã
1.4以éã @ã®åäœã¯@ã«è¿ã¥ããŸããã åŒãæ¬ èœããŠããå Žåã$ã¹ã³ãŒãå ã®å¯Ÿå¿ããã¡ãœãããæ¬ èœããŠããŸãã ã¢ã¯ã»ã¹ãããšã undefinedãè¿ãé¢æ°ã®ä»£ããã«undefinedãååŸããŸãã
眮æãã£ã¬ã¯ãã£ãã®ããããã£
1.3ããã¯éæšå¥šã«ãªãã次ã®ã¡ãžã£ãŒãªãªãŒã¹ã§åé€ããå¿ èŠããããŸãã
ããã¯ãå±æ§ã®ããŒãžã«åé¡ããããšããäºå®ã«ãã£ãŠèª¬æãããŸãã
詳现ïŒ
çµã¿åãããå Žå
ãš
ãããã
åŒãç¡å¹ã§ãããšãã察å¿ãããšã©ãŒããããŸãã
ãŸãããã®ãããªæ什ã®ã«ãã»ã«åã¬ãã«ãäžè¬çã§äžååã§ãã
ãã®ããŒãã«é¢ããHolivarã¯ãã¡ãããå ¥æã§ããŸã ã
<div ng-class="{hasHeader: true}"></div>
ãš
<div ng-class="{active: true}"></div>
ãããã
<div ng-class="{active: true}{hasHeader: true}"></div>
åŒãç¡å¹ã§ãããšãã察å¿ãããšã©ãŒããããŸãã
ãŸãããã®ãããªæ什ã®ã«ãã»ã«åã¬ãã«ãäžè¬çã§äžååã§ãã
ãã®ããŒãã«é¢ããHolivarã¯ãã¡ãããå ¥æã§ããŸã ã
$ãªãã¶ãŒããŒ
ããŒãžã§ã³1.3ãããå±æ§ãªãã¶ãŒããŒãåé€ãã䟿å©ãªæ¹æ³ãããããåŸãããŸãããattr.observeãåŒã³åºããããšãdestructoré¢æ°ãïŒwatchãšåæ§ã«ïŒæ»ããŸãã 以åã圌ã¯ãªãã¶ãŒããŒã®æ©èœãžã®ãªã³ã¯ãè¿ããŸããã
ããŠããªãã¶ãŒããŒã®æ©èœãžã®ãªã³ã¯ãäœæããã«ã¯ããŸãã©ããã«ä¿åããå¿ èŠããããŸãã
äŸïŒ
<1.3ïŒ
ä»ã®ããã«ïŒ
directive('directiveName', function() { return { link: function(scope, elm, attr) { var observer = attr.$observe('someAttr', function(value) { console.log(value); }); } }; });
ä»ã®ããã«ïŒ
directive('directiveName', function() { return { link: function(scope, elm, attr) { var observer = function(value) { console.log(value); }; var destructor = attr.$observe('someAttr', observer); destructor(); // } }; });
å€éšã¹ã³ãŒãã¢ã¯ã»ã¹
å€ç«ãããã£ã¬ã¯ãã£ããå®çŸ©ãããŠããèŠçŽ ã®å±æ§ãä»ããŠãå€ç«ããã¹ã³ãŒãããããã£ãååŸã§ããªããªããŸããã
äŸïŒ
次ã®ãã£ã¬ã¯ãã£ããæå®ãããŠããŸãã
<1.3ïŒ
1.3+ïŒ
app.controller('testController', function($scope) { $scope.controllerScope = true; }); app.directive('testDirective', function() { return { template:'<span ng-if="directiveScope">world!</span>', scope: {directiveScope: '='}, controller: function($scope) {}, replace: true, restrict: 'E' } });
<1.3ïŒ
Hello <test-directive directive-scope="controllerScope"></test-directive> // Hello
1.3+ïŒ
Hello <test-directive directive-scope="controllerScope"></test-directive> // Hello world!
ngModelController
$ setViewValueïŒïŒ
$ setViewValueïŒïŒã®åäœãå°ãå€æŽããã以åã®ããã«$ modelValueã®å€æŽãããã«ã¹ããŒãããªããªããŸããã
ããã§ãã¢ãã«ã¯2ã€ã®ngModelOptionsèšå®ã«å¿ããŠæŽæ°ãããç¹ã«æ¬¡ã®ããã«ãªããŸãã
- updateOn ïŒãã®ããªã¬ãŒã§æå®ãããã€ãã³ãã®ãããããåŒã³åºããããŸã§ãã¢ãã«ã¯æŽæ°ãããŸãã
- ãããŠã³ã¹ ïŒ ãããŠã³ã¹ã®ããããã§æå®ãããæéãçµéãããŸã§ãã¢ãã«ã¯æŽæ°ãããŸãã
ããã©ã«ãã§ã¯ã updateOnã¯defaultã§ããã debounceã¯0ã§ããããã$ modelValueã¯ä»¥åãšåæ§ã«å³åº§ã«å®è¡ãããŸãã
ãã ããå€ãã³ãŒãã䜿çšããå Žåã¯ãäžèšã®æ©èœãæ€èšãã䟡å€ããããŸãã
$ commitViewValue
updateOnãšdebounceãç¡èŠããŠãä»»æã®ã³ã¹ãã§å³åº§ã«$ modelValueãæŽæ°ããå Žåã¯ã $ commitViewValueïŒïŒã䜿çšããŸãã
$ commitViewValueïŒïŒã¯åŒæ°ãåããŸããã 圌ã¯ä»¥åãææžåãããŠããªãåæ€èšŒåŒæ°ã䜿çšããŠããŸãã
$$ lastCommittedViewValueã§ãã£ãŠãã匷å¶çã«åæ€èšŒãšé¢é£ããã»ã¹ãéå§ããããã®ããã¯ãšããŠã®ãã©ã€ããŒãAPI
æŽæ°ãããŠããŸããããæè¿ã®ããŒãžã§ã³ã§ã¯åé€ãããŠããŸãã
$ cancelUpdateïŒïŒ
$ rollbackViewValueïŒïŒã«ååãå€æŽãããŸããã
ãã®åŒã³åºãã«ããã $ viewValueãç¶æ $$ lastCommittedViewValueã«ãããŒã«ããã¯ãããé²è¡äžã®ãã¹ãŠã®ãããŠã³ã¹ããã£ã³ã»ã«ããŠããã¥ãŒïŒå ¥åãªã©ïŒãåæç»ã§ããŸãã
äŸïŒ
<1.3ïŒ
1.3+ïŒ
$scope.resetWithCancel = function (e) { $scope.myForm.myInput.$cancelUpdate(); $scope.myValue = ''; };
1.3+ïŒ
$scope.resetWithCancel = function (e) { $scope.myForm.myInput.$rollbackViewValue(); $scope.myValue = ''; };
å ¥åïŒæ¥ä»ãæå»ãçŸå°æéãæãé±
ããŒãžã§ã³1.3以éã Angularã¯éåžžãæ°å€ã«é¢é£ããHTML5å ¥åããµããŒãããŠããŸãã
ãã®ãããªå ¥åã®ngã¢ãã«ã§ã¯ã Dateãªããžã§ã¯ãã¯å³å¯ã«
ãããã®å ¥åããµããŒãããŠããªãå€ããã©ãŠã¶ãŒã§ã¯ããŠãŒã¶ãŒã«ã¯ããã¹ãã衚瀺ãããŸãã ãã®ãããªå Žåãå¿ èŠãªæ¥ä»ã«æ£ããISO圢åŒãå ¥åããå¿ èŠããããŸãã
æ€èšŒ
$ãšã©ãŒåé
[ã³ããã]以åã¯ã $ setValidityã䜿çšããŠã³ã³ãããŒã«ã®æå¹æ§ãæåã§å¶åŸ¡ããããšã«ãã ãä»»æã®ããããã£ã$ãšã©ãŒã«æ ŒçŽã§ããŸããã
ããŒãžã§ã³1.3以éãæçµçãªæ€èšŒã¯ã $ãšã©ãŒããã·ã¥ã空ãã©ããã«ãã£ãŠç°ãªããŸãã ngModelCtrlã§ããããã£ãã¹ããŒ$æåã§ãšã©ãŒãçºçããããããæéå ã«åé€ããªããšããã®ããããã£ã®å€ã«é¢ä¿ãªããæ°žä¹ ã«ç¡å¹ãªã³ã³ãããŒã«ãååŸãããŸãã
$ setValidityã«ãªããŸã
[ã³ããã]$ setValidityã䜿çšãããšã nameãšresultã® 2ã€ã®åŒæ°ãåãå ¥ããããšã«ãããç¹å®ã®ã³ã³ãããŒã«ããããã£ã®æå¹æ§ãèšå®ã§ããŸã ã
以åã¯ã çµæ㯠ãæž¡ãããå 容ã«é¢ä¿ãªããåžžã«trueãŸãã¯falseã«ãã£ã¹ããããŠããŸããã
ããŒãžã§ã³1.3以éã $ setValidityã¯ã resultã«æž¡ãããfalse ã undefined ã nullãåºå¥ãå§ããŸã ã çµæãæ£ç¢ºã«ããŒã«å€ã§ããããšã確èªãã䟡å€ããããŸãã
ããšãã°ãéåæããªããŒã¿ãŒã®å éšã§ã¯ã undefinedããã³nullã®å€ã䜿çšãããŸãã ãã®ããããã¹ãŠã®åæããªããŒã¿ãŒãæå¹ã§ã¯ãªãå Žåãéåæã®ããªããŒã¿ãŒã®å€ã¯nullã«èšå®ãããŸã ã åæããªããŒã¿ãŒã®æºåãã§ããŠãããéåææ€èšŒãéå§ãããŠããå Žåã ä¿çäžãããéããããªããŒã¿ãŒå€ã¯undefinedã«èšå®ãããŸãã
$ããŒãµãŒãšæªå®çŸ©ã
[ã³ããã]以åã¯ãããšãã°ããããå£ãããå Žåã $ããŒãµãŒãã§ãŒã³ã«undefinedãã¹ããŒã§ããŸããã
ããŒãžã§ã³1.3以éãããŒãµãŒã¯æªå®çŸ©ã®åŠçãããã {parseïŒtrue}ã$ errorã«èšå®ããããšã§å¶åŸ¡ãç¡å¹ã«ããªããªããŸãã ã
ããã¯ã $ viewValue ïŒ ãŸã èšå®ãããŠããªã ïŒã®ãšãã«ããŒãµãŒãèµ·åããªãããã«ããããã«è¡ãããŸã
ngPattern
[ã³ããã]1.4.5以éã ngPatternãã£ã¬ã¯ãã£ãã¯ã $ parseValuesãã§ãŒã³ãæ©èœããåã«ã $ viewValue ïŒä»¥åã¯$ modelValueã«åºã¥ããŠããïŒã«åºã¥ããŠæ€èšŒããŸãã
ããã¯ãããŒãµãŒã$ viewValueãããããDateããã³Numberã«å€æããããã«ã å ¥å[æ¥ä»]ããã³å ¥å[çªå·]ãæ€èšŒãããªãå Žåã®åé¡ãåå ã§ãã
ãã®ãã£ã¬ã¯ãã£ãã§$ viewValue修食åã䜿çšãã以åã®ããã«æ£ç¢ºã«$ modelValueããã§ãã¯ããå¿ èŠãããå Žåã¯ãã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã䜿çšããå¿ èŠããããŸãã
äŸïŒ
.directive('patternModelOverwrite', function patternModelOverwriteDirective() { return { restrict: 'A', require: '?ngModel', priority: 1, compile: function() { var regexp, patternExp; return { pre: function(scope, elm, attr, ctrl) { if (!ctrl) return; attr.$observe('pattern', function(regex) { /** * The built-in directive will call our overwritten validator * (see below). We just need to update the regex. * The preLink fn guaranetees our observer is called first. */ if (isString(regex) && regex.length > 0) { regex = new RegExp('^' + regex + '$'); } if (regex && !regex.test) { //The built-in validator will throw at this point return; } regexp = regex || undefined; }); }, post: function(scope, elm, attr, ctrl) { if (!ctrl) return; regexp, patternExp = attr.ngPattern || attr.pattern; //The postLink fn guarantees we overwrite the built-in pattern validator ctrl.$validators.pattern = function(value) { return ctrl.$isEmpty(value) || isUndefined(regexp) || regexp.test(value); }; } }; } }; });
ngMinlength / ngMaxlength
1.3以éã ngMinlengthããã³ngMaxlengthãã£ã¬ã¯ãã£ãã¯ã $ viewValue ïŒä»¥åã¯$ modelValueã«åºã¥ããŠããŸãã ïŒã«åºã¥ããŠæ€èšŒãå®è¡ããŸãã
ããã«ããããããã®ãã£ã¬ã¯ãã£ãããé»è©±ã«å ¥ãããã®ãã¹ã¯ãªã©ã $ viewValueãå€æŽãããã£ã¬ã¯ãã£ããšäžç·ã«äœ¿çšãããšã誀ã£ãæ€èšŒã«ã€ãªããå¯èœæ§ããããŸãã
åé¡ãåé¿ããã«ã¯ã2ã€ã®è§£æ±ºçããããŸãã
- $ viewValueã«åŸã£ãŠæ倧æåæ°ãå€æŽããŸã ïŒããšãã°ããxx-xxããšãã圢åŒã®ãã¹ã¯ãã¢ãã«ã«ãxxxxãã®ã¿ãå«ãŸããå Žåã以åã®ããã«4ã§ã¯ãªãmaxlength =ã5ããšããŠèæ
®ãããå¿
èŠããããŸãïŒ
- $ modelValueããã§ãã¯ããç¬èªã®ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã䜿çšããŸãã ãã ããä»æ§ã«ãããšãå
¥åãããæåæ°ãå¶éãããããã maxlengthã«åé¡ãããå¯èœæ§ããããŸãããã®ãããå¶éãå®è£
ããå¿
èŠããããŸãã
ã»ãšãã©ã®å Žåãæåã®ãªãã·ã§ã³ãæãåé¡ã®å°ãªããã®ãšããŠäœ¿çšããããšããå§ãããŸãã
2çªç®ã®ãªãã·ã§ã³ã¯ãminLengthã«åœ¹ç«ã¡ãŸãã äºåã«næåãå ¥åãããŠãããã¹ã¯ä»ãã®ãªãã·ã§ã³å ¥åãããå ŽåïŒããšãã°ãã+ 7ããèšå®ãããé»è©±ã®å ¥åïŒãããã¯ãminLengthã空ã§ããéããã£ãŒã«ããæ€èšŒããªãããã§ãã
ã«ã¹ã¿ã maxlengthã®äŸ
(function (angular) { 'use strict'; angular .module('mainModule') .directive('maxModelLength', maxlengthDirective); function maxlengthDirective () { return { restrict: 'A', require: '?ngModel', link: function (scope, elm, attr, ctrl) { if (!ctrl) { return; } var maxlength = -1; attr.$observe('maxModelLength', function (value) { var intVal = parseInt(value); maxlength = isNaN(intVal) ? -1 : intVal; ctrl.$validate(); }); ctrl.$validators.maxlength = function (modelValue, viewValue) { return (maxlength < 0) || ctrl.$isEmpty(modelValue) || (String(modelValue).length <= maxlength); }; /* * , - maxlength * , * */ elm.bind('keydown keypress', function (event) { var stringModel = String(ctrl.$modelValue); if (maxlength > 0 && !ctrl.$isEmpty(ctrl.$modelValue) && stringModel.length >= maxlength) { if ([8, 37, 38, 39, 40, 46].indexOf(event.keyCode) === -1) { event.preventDefault(); } } }); } }; } })(angular);
ã«ã¹ã¿ã æå°é·ã®äŸ
(function (angular) { 'use strict'; angular .module('mainModule') .directive('minModelLength', minlengthDirective); function minlengthDirective () { return { restrict: 'A', require: '?ngModel', link: function (scope, elm, attr, ctrl) { if (!ctrl) { return; } var minlength = 0; attr.$observe('minModelLength', function (value) { minlength = parseInt(value) || 0; ctrl.$validate(); }); ctrl.$validators.minlength = function (modelValue, viewValue) { return ctrl.$isEmpty(modelValue) || String(modelValue).length >= minlength; }; } }; } })(angular);
ä»®æ³ngModelåé¡ïŒ
çŽæ¥ããŒã¿å ¥åãç®çãšããªãèŠçŽ ïŒããšãã°ãã«ãŒãngModelã§åäœããè€æ°ã®å ¥åãå«ããã£ã¬ã¯ãã£ãã®ã«ãŒãïŒã§ngMinlength / ngMaxlengthã䜿çšããæ°å€ããŒã¿ã䜿çšãããšã誀ã£ãããŒã¿æ€èšŒãåãåããŸãïŒåžžã«ãšã©ãŒãçºçããŸãïŒ ã
ããå ·äœçã«ã¯ã æ°å€ã¯åžžã«$ viewValueã«æ ŒçŽãããŸã ãããã¯ãããªããŒã¿ãŒããã§ãã¯ã§ããªãããã§ãã .lengthãååŸã§ããŸããã
ãªããããèµ·ãã£ãŠããã®ã§ããïŒ
$ Compileã«ã¯åºæ¬çãªãã£ã¬ã¯ãã£ããå«ãŸããŠããŸãã ããšãã°ã inputããã³textareaã®å Žåã inputDirectiveã³ã³ãããŒã«ãåŒã³åºãããŸã ãããã¯attr.typeãåãåããããã«åºã¥ããŠinputTypeã³ã¬ã¯ã·ã§ã³ã®é¢æ°ã®1ã€ãåŒã³åºããŸãã ããã¹ãåã®å Žåãããã¯ããããtextInputTypeã§ãããå¶åŸ¡ãstringBasedInputTypeé¢æ°ã«ã¹ããŒããŸã ããã®é¢æ°ã¯ãå€ã$ formattersã®æååã«å€æããããã®ã³ãŒããè¿œå ããŸãã
ngModelã inputãªã©ã®æ¢åã®åºæ¬èŠçŽ ã«é¢é£ä»ããããŠããªãããããšãã°åçŽãªdivãŸãã¯ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã§ãã³ã°ããå ŽåãããŒã¿ã¯æååãžã®è¿œå ã®å€æãªãã§$ viewModelã« ã ãã®ãŸãŸ ãããŒã«ããããã£ã¬ã¯ãã£ãã®ãšã©ãŒãçºçããŸãã ngMaxlengthã®ãããªãã£ã«ã¿ãŒ ã
, , , .
Plunker .
ngModelã inputãªã©ã®æ¢åã®åºæ¬èŠçŽ ã«é¢é£ä»ããããŠããªãããããšãã°åçŽãªdivãŸãã¯ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ãã§ãã³ã°ããå ŽåãããŒã¿ã¯æååãžã®è¿œå ã®å€æãªãã§$ viewModelã« ã ãã®ãŸãŸ ãããŒã«ããããã£ã¬ã¯ãã£ãã®ãšã©ãŒãçºçããŸãã ngMaxlengthã®ãããªãã£ã«ã¿ãŒ ã
, , , .
Plunker .
ã¹ã³ãŒããšãã€ãžã§ã¹ã
$ id
ä»ã§ã¯æå³ããããŸãã
以åã¯ãæ°å€ãã¹ã³ãŒãã®èšç®ã«ååã§ãªãå¯èœæ§ããããšããæžå¿µã®ããã«ãæååã䜿çšããŠ$ idã瀺ãããšã«ããŸããïŒå®éã«ã¯['0'ã '0'ã '0']ã®åœ¢åŒã®é åã§ãïŒããããã«é¢ããæžå¿µããããŸãæ³æ¡ã¯å®çŸããŸããã§ããã
代ããã«ãå€ãã®ã¹ã³ãŒããäœæãããšãïŒããšãã°ã倧ããªããŒãã«ãæäœãããšãïŒã«äœåãªè² è·ïŒæ°ããªç§è¿œå ïŒãçºçããŸããããã©ã€ã ã«åãæ¿ãããšããã®åé¡ã解決ããŸãã
äŸïŒ
<1.3: [ Plunker]
1.3+: [ Plunker]
console.log($rootScope.$id); // => 001
1.3+: [ Plunker]
console.log($rootScope.$id); // => 1
æŸéããŠæŸåºãã
ã€ãã³ããé åžãã§ãŒã³ã®æåŸã«å°éãããããã«ãcurrentScopeãnullã«èšå®ããŸãã
ããã¯ã誰ããéåæé¢æ°ããã€ãã³ãã«ã¢ã¯ã»ã¹ããããšãããšãã«event.currentScopeã誀ã£ãŠäœ¿çšãããå Žåã®è¿œè·¡ãé£ãããã°ãåå ã§ãã
以åã¯ããã®å Žåã®event.currentScopeã¯ãã§ãŒã³å ã®æåŸã®$ã¹ã³ãŒãã«çãããéãã«ã¢ããªã±ãŒã·ã§ã³ã®èª€åäœãåŒãèµ·ãããŠããŸãããevent.currentScope
ã䜿çšããå Žåã®åæ§ã®ã±ãŒã¹ã§ã¯ããšã©ãŒãçºçããŸããevent.currentScopeã«
éåæçã«ã¢ã¯ã»ã¹ããã«ã¯ãevent.targetScopeã䜿çšããå¿ èŠããããŸãã
äŸïŒ
scope:
customEvent GrandChildCtrl
<1.3: [ Plunker]
1.3+: [ Plunker]
001 ($rootScope) â 002 ($scope of ParentCtrl) â 003 ($scope of ChildCtrl) â 004 ($scope of GrandChildCtrl)
customEvent GrandChildCtrl
<1.3: [ Plunker]
.controller('ParentCtrl', function($scope, $timeout) { $scope.$on('customEvent', function(event) { console.log(event.currentScope); // $id 002 $timeout(function() { console.log(event.targetScope) // => $id 004 console.log(event.currentScope) // => $id 001 }); }) }) .controller('ChildCtrl', function($scope, $timeout) { $scope.$on('customEvent', function(event) { console.log(event.currentScope); // $id 003 $timeout(function() { console.log(event.targetScope) // => $id 004 console.log(event.currentScope) // => $id 001 }); }) })
1.3+: [ Plunker]
.controller('ParentCtrl', function($scope, $timeout) { $scope.$on('customEvent', function(event) { console.log(event.currentScope); // $id 2 $timeout(function() { console.log(event.targetScope) // => $id 4 console.log(event.currentScope) // => null }); }) }) .controller('ChildCtrl', function($scope, $timeout) { $scope.$on('customEvent', function(event) { console.log(event.currentScope); // $id 3 $timeout(function() { console.log(event.targetScope) // => $id 4 console.log(event.currentScope) // => null }); }) })
httpããã³ãªãœãŒã¹
JSONããªããã£ã
[ã³ããã]ããŒãžã§ã³1.3以éãããªããã£ããå«ãContent-TypeïŒapplication / jsonã®å¿çã¯JSONãšããŠè§£æããå§ããŸãã
äžè¬ã«ãããã¯ãã°ä¿®æ£ã§ããããã«ãããåçãæäœãããšãã«æŸèæãåé¿ã§ããŸãããå Žåã«ãã£ãŠã¯æ¢åã®ã³ãŒããç Žæããå¯èœæ§ããããŸãã
äŸïŒ
«OK» , , .
<1.3:
1.3+:
<1.3:
response === 'OK' // => false response === '"OK"' // => true
1.3+:
response === 'OK' // => true response === '"OK"' // => false
$ http transformRequest
ããŒãžã§ã³1.4以éãtransformRequesté¢æ°ã¯ãµããŒããããªããªãããªã¯ãšã¹ãããããŒã¯å€æŽãããŸããã代ããã«ãèŠæ±ãã©ã¡ãŒã¿ãŒã®headersããããã£ãšãç®çã®ããããŒã«å¯Ÿå¿ããgetteré¢æ°ã䜿çšãã䟡å€ããããŸããconfig
ãªããžã§ã¯ãã¯ãé¢æ°ã®æåã®åŒæ°ã®ãµããããŸããããã«ãããããããŒãåçã«å®çŸ©ããã³èšå®ã§ããŸãã
äŸïŒ
'X-MY_HEADER'
<1.4:
1.4+:
<1.4:
function requestTransform(data, headers) { headers = angular.extend(headers(), { 'X-MY_HEADER': 'test' }); return angular.toJson(data); }
1.4+:
$http.get(url, { headers: { 'X-MY_HEADER': function(config) { return 'test'; } } })
$ HTTPã€ã³ã¿ãŒã»ãã¿ãŒ
$ httpProviderã®responseInterceptorsã³ã¬ã¯ã·ã§ã³ã¯ãã§ã«éæšå¥šã®ã¹ããŒã¿ã¹ã«ãªã£ãŠããã2ã€ã®ç°ãªãAPIïŒ1ã€ã¯å®å šã«æããã§ã¯ãªãïŒãæã£ãŠãããããããŸããŸãªå°æãæããŸãããããŒãžã§ã³1.3以éããã®ã³ã¬ã¯ã·ã§ã³ãšãã®æ©èœã¯[åé€]ãããŠããŸãã代ããã«ãã€ã³ã¿ãŒã»ãã¿ãŒãç»é²ããããã®æ°ããééçãªAPIãå©çšå¯èœã§ãã
äŸïŒ
myHttpInterceptor .
< 1.3: [ Plunker]
1.3+: [ Plunker]
< 1.3: [ Plunker]
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) { return function(promise) { return promise.then(function(response) { // success return response; }, function(response) { // error if (canRecover(response)) { return responseOrNewPromise } return $q.reject(response); }); } }); $httpProvider.responseInterceptors.push('myHttpInterceptor');
1.3+: [ Plunker]
$provide.factory('myHttpInterceptor', function($q) { return { response: function(response) { // success return response; }, responseError: function(response) { // error if (canRecover(response)) { return responseOrNewPromise } return $q.reject(response); } }; }); $httpProvider.interceptors.push('myHttpInterceptor');
$ httpBackendããã³JSONP
ããã§ãè§åºŠã¯ãæåãã€ãã³ãã§ãšã©ãŒããã£ããããJSONPã®ç©ºã®åçïŒã³ãŒã«ããã¯ã§ããŒã¿ãæ¬ èœïŒã¯ãšã©ãŒã«ãªããŸããïŒä»¥åã«ãšã©ãŒãçæããã¹ããŒã¿ã¹ã-2ã«èšå®ïŒã
次ã®ããšãç¥ã£ãŠããïŒãŸãã¯ç¥ããªãïŒã®ã¯èå³æ·±ãããšã§ãã
onload onerror JSONP script .
jQuery event .
, , .
$.data(«events») , jqLite .
jQuery event .
, , .
$.data(«events») , jqLite .
IE8ïŒonreadystatechangedã€ãã³ãã¯ãµããŒããããªããªããŸããã
$ãªãœãŒã¹
$ãªãœãŒã¹ã€ã³ã¹ã¿ã³ã¹ã§toJsonïŒïŒãåŒã³åºããšãåäžã®$ã§å§ãŸããã¹ãŠã®ããããã£ã®ããã«ãã·ãªã¢ã«åäžã«ä»¥åã«åãåããã$ promiseããã³$ resolveããããã£ãå«ãŸããŸããäžèšã®toJsonïŒïŒã®å€æŽã«ãããšã$ã§å§ãŸãããããã£ã¯ã·ãªã¢ã«åãããªããªããŸãããçŸåšã$$ã§å§ãŸãããããã£ã®ã¿ãã·ãªã¢ã«åãããŸããããã«åºã¥ããŠãã·ãªã¢ã«åããã$ãªãœãŒã¹ã«ã¯ãããã®ããããã£ãå«ãŸãããšäºæ³ãããŸãããããã§ã¯ãããŸãããå ·äœçã«ã¯ã圌ã¯ã·ãªã¢ã«åäžã«ããã2ã€ã®ããããã£ãåãåããŸãã
ãŠãŒã¶ãŒãè¿œå ããããããã£ãå«ãä»ã®ãã¹ãŠã®ããããã£ã¯ã·ãªã¢ã«åãããçµæã®jsonã«å«ãŸããŸãã
$ã€ã³ãžã§ã¯ã
ã¢ãžã¥ãŒã«ïŒ.configïŒïŒããã³.providerïŒïŒ
以åã¯ã.providerïŒïŒãæ©èœããåã«.configïŒïŒãåŒã³åºãããšãå¯èœã§ããã
ããŒãžã§ã³1.3以éããã®åäœã¯äžå¯èœã§ããã¹ãŠã®.providerïŒïŒã¢ãžã¥ãŒã«ãæ©èœããåŸã«ã®ã¿.configïŒïŒãåŒã³åºãããŸãã
äŸïŒ
<1.3: [ Plunker]
Provider 1, Config, Provider 2
1.3+: [ Plunker]
Provider 1, Provider 2, Config
app .provider('$rootProvider1', function() { console.log('Provider 1'); this.$get = function() {}; }) .config(function() { console.log('Config'); }) .provider('$rootProvider2', function() { console.log('Provider 2'); this.$get = function() {}; });
<1.3: [ Plunker]
Provider 1, Config, Provider 2
1.3+: [ Plunker]
Provider 1, Provider 2, Config
ngAnimate
ãã¹ãŠã®æ¹æ³
以åã¯ããã¹ãŠã®$ animateã¡ãœããã®æåŸã®åŒæ°ã¯doneã³ãŒã«ããã¯ã§ãã¢ãã¡ãŒã·ã§ã³ãçµäºãããšãã«å®è¡ãããŠããŸããã
ããŒãžã§ã³1.3以éããªãã·ã§ã³ã¹ã¿ã€ã«ã®ã»ãããããã«æž¡ãããèŠçŽ ã«é©çšãããŸããå®äºãã
代ããã«ããã¹ãŠã®é¢æ°ãpromiseãè¿ãããã«ãªããŸããããã®è§£æ±ºã¯ã¢ãã¡ãŒã·ã§ã³ã®å®äºãæå³ããŸãã
animate.enterïŒïŒããã³animate.moveïŒïŒ
ãããã®ã¡ãœããã«ã¯4ã€ã®åŒæ°ïŒèŠçŽ ã芪ãåŸããªãã·ã§ã³ïŒããããŸãã
以åã¯ãafteråŒæ°ãæå®ãããªãã£ãå Žåãæå®ãããelementã®åŸã«æ°ããèŠçŽ ãè¿œå ãããæå®ãããå Žåãafterã®åŸã«è¿œå ãããŸããã
åé¡ã¯ãåæ§ã®APIã§ã芪ã³ã³ããã®äžéšã«æ°ããèŠçŽ ãè¿œå ã§ããªãããšã§ãã
éå§ããŒãžã§ã³1.3ã§åŒæ°ããããŠããå ŽåãåŸã«æå®ãããŠããªãå Žåããã®èŠçŽ ã¯ãã³ã³ããã®äžéšã«è¿œå ããã芪ã
ãããã£ãŠãæ°ããèŠçŽ ãæ¿å ¥ããç¹å®ã®èŠçŽ ãæå®ããå¿ èŠããããŸãã
äŸïŒ
$animate.enter
<1.3:
1.3+:
<1.3:
// `element` `$animate.enter(element, parent);`
1.3+:
// `parent` `$animate.enter(element, parent);` // `element` `$animate.enter(element, parent, angular.element(parent[0].lastChild));`
ãã£ã«ã¿ãŒ
å éšã³ã³ããã¹ã
[ã³ããã]ãã®ã³ã³ãããŒã«ã®å éšç¶æ³ïŒä»¥åã¯ããã¹ãŠã®ãã£ã«ã¿ã¯ãææžåãããŠããªãæ©èœãæã£ãŠãããããã¯åŒã°$ã¹ã³ãŒããã£ã«ã¿ãŒãããªã¬ãŒãããŸãããã
ãããã§ããªãçç±ãšæ£ããæ¹æ³ïŒ
, , $scope . , ng-repeat .
Andy Joslin's :
1.3 , $scope ( this ) undefined .
$scope , ** **, $scope 10%, $scope $digest
Error: 10 $digest() iterations reached. Aborting! ã
:
ng-repeat:
item in (filterResults = (items | filter:query)) , , as : item in items | filter:query as filterResults) .
Andy Joslin's :
yourModule.filter("as", function($parse) { return function(value, path) { return $parse(path).assign(this, value); }; });
1.3 , $scope ( this ) undefined .
$scope , ** **, $scope 10%, $scope $digest
Error: 10 $digest() iterations reached. Aborting! ã
:
- : , .
- $scope .
ng-repeat:
item in (filterResults = (items | filter:query)) , , as : item in items | filter:query as filterResults) .
ãã£ã«ã¿ãŒ
çŸåšã§ã¯ãé åã§ã®ã¿æ©èœããŸãã
ããŒãžã§ã³1.4ã§ã¯ããªããžã§ã¯ãã§ãã£ã«ã¿ãŒãåŒã³åºãããšãããšãšã©ãŒãçºçããŸãã以åã¯ãåã«ããµã€ã¬ã³ããã«ç©ºã®é åãè¿ããŸããã
ãªããžã§ã¯ããå埩åŠçããã«ã¯ããªããžã§ã¯ããé åã«å€æããã«ã¹ã¿ã ãã£ã«ã¿ãŒã䜿çšããããšããå§ãããŸãã
limitTo
以åã¯ãç¡å¹ãªå¶éãlimitToã«æž¡ãããå ŽåïŒããšãã°ãundefinedïŒã空ã®é åãŸãã¯æååãè¿ããŠããŸããã
ããŒãžã§ã³1.4以éãå¶éãæ£ãããªãå Žåãå ã®å ¥åããŒã¿ãã€ãŸã ãã£ã«ã¿ãé©çšããªãé åãŸãã¯æååã
ngCookies
$ã¯ãããŒ
ããŒãžã§ã³1.4以éããã©ãŠã¶Cookieã¯$ cookiesãµãŒãã¹ãªããžã§ã¯ãã«ã³ããŒãããªããªããããŒã¿ã¯ã»ãã¿ãŒ/ã²ãã¿ãŒã§ã¯ãªããå€ãæäœããããã®ããéæãªAPIãä»ããŠåŠçãããŸãã
- åŸã
- 眮ã
- getObject
- putObject
- getAll
- åãé€ã
ããã¯ããªããžã§ã¯ãã«é¢é£ããŒã¿ãå«ãŸããªããªã£ããšãã®ããŒã¿åæãã°ã«ãããã®ã§ããã€ãŸãããŠã©ããã£ãŒã䜿çšããŠãªããžã§ã¯ããä»ããCookieã®å€æŽã远跡ããããšã¯ã§ããªããªããŸãã
ãã®ãããªæäœã¯ãããšãã°ããã©ãŠã¶ãŒã®ã¿ãéã®éä¿¡ã®ããã«éå»ã«å¿ èŠã§ããããæè¿ã§ã¯ãããšãã°localStorageãªã©ã®ãã䟿å©ãªããŒã«ããããŸãã
$ cookieStore
ããŒãžã§ã³1.4以éã$ cookieStoreãµãŒãã¹ã¯éæšå¥šã¹ããŒã¿ã¹ãåãåãããã¹ãŠã®äŸ¿å©ãªããžãã¯ã$ cookieãµãŒãã¹ã«è»¢éããã$ cookieStoreã«ã¢ã¯ã»ã¹ãããšçŸåš$ cookieã€ã³ã¹ã¿ã³ã¹ãè¿ãããŸãã
çµè«ïŒ
ãããžã§ã¯ããããã¬ãŒã ã¯ãŒã¯ã®ãã°ãšææžåãããŠããªãæ©èœã«åºã¥ããŠãèªæã§ãªããœãªã¥ãŒã·ã§ã³ã®
ã¢ãã¡ãŒã·ã§ã³ãã¢ããªã±ãŒã·ã§ã³ã®æ€èšŒã«è§åºŠã®æ段ã䜿çšããªãã£ã人ã«ãšã£ãŠã¯ããŸã£ããçã¿ã¯ãããŸããã
次ã®èšäºã§ã¯ãæ°ããããŒãžã§ã³ã®ãã¹ãŠã®å©ç¹ãšããããã®å©ããåããŠçç£æ§ãåäžãããæ¹æ³ã«ã€ããŠèª¬æããŸãã
移è¡äžã«ä»ã®èå³æ·±ãåé¡ã«ééããå Žåã¯ãã³ã¡ã³ãã§å ±æããŠãã ããã