@@ -665,36 +665,39 @@ angular.module('ngMessages', [])
665
665
*
666
666
* @param {expression } ngMessageDefault|when no ngMessage matches.
667
667
*/
668
- . directive ( 'ngMessageDefault' , ngMessageDefaultDirectiveFactory ( 'AE' ) ) ;
668
+ . directive ( 'ngMessageDefault' , ngMessageDirectiveFactory ( 'AE' , true ) ) ;
669
669
670
670
671
- function ngMessageDirectiveFactory ( restrict ) {
671
+ function ngMessageDirectiveFactory ( restrict , isDefault ) {
672
672
return [ '$animate' , function ( $animate ) {
673
673
return {
674
674
restrict : 'AE' ,
675
675
transclude : 'element' ,
676
676
terminal : true ,
677
677
require : '^^ngMessages' ,
678
678
link : function ( scope , element , attrs , ngMessagesCtrl , $transclude ) {
679
- var commentNode = element [ 0 ] ;
680
-
681
- var records ;
682
- var staticExp = attrs . ngMessage || attrs . when ;
683
- var dynamicExp = attrs . ngMessageExp || attrs . whenExp ;
684
- var assignRecords = function ( items ) {
685
- records = items
686
- ? ( isArray ( items )
687
- ? items
688
- : items . split ( / [ \s , ] + / ) )
689
- : null ;
690
- ngMessagesCtrl . reRender ( ) ;
691
- } ;
692
-
693
- if ( dynamicExp ) {
694
- assignRecords ( scope . $eval ( dynamicExp ) ) ;
695
- scope . $watchCollection ( dynamicExp , assignRecords ) ;
696
- } else {
697
- assignRecords ( staticExp ) ;
679
+ var commentNode , records , staticExp , dynamicExp ;
680
+
681
+ if ( ! isDefault ) {
682
+ commentNode = element [ 0 ] ;
683
+ staticExp = attrs . ngMessage || attrs . when ;
684
+ dynamicExp = attrs . ngMessageExp || attrs . whenExp ;
685
+
686
+ var assignRecords = function ( items ) {
687
+ records = items
688
+ ? ( isArray ( items )
689
+ ? items
690
+ : items . split ( / [ \s , ] + / ) )
691
+ : null ;
692
+ ngMessagesCtrl . reRender ( ) ;
693
+ } ;
694
+
695
+ if ( dynamicExp ) {
696
+ assignRecords ( scope . $eval ( dynamicExp ) ) ;
697
+ scope . $watchCollection ( dynamicExp , assignRecords ) ;
698
+ } else {
699
+ assignRecords ( staticExp ) ;
700
+ }
698
701
}
699
702
700
703
var currentElement , messageCtrl ;
@@ -713,7 +716,7 @@ function ngMessageDirectiveFactory(restrict) {
713
716
// to deregister the message from the controller
714
717
currentElement . on ( '$destroy' , function ( ) {
715
718
if ( currentElement ) {
716
- ngMessagesCtrl . deregister ( commentNode ) ;
719
+ ngMessagesCtrl . deregister ( commentNode , isDefault ) ;
717
720
messageCtrl . detach ( ) ;
718
721
}
719
722
} ) ;
@@ -727,7 +730,7 @@ function ngMessageDirectiveFactory(restrict) {
727
730
$animate . leave ( elm ) ;
728
731
}
729
732
}
730
- } ) ;
733
+ } , isDefault ) ;
731
734
}
732
735
} ;
733
736
} ] ;
@@ -740,47 +743,3 @@ function ngMessageDirectiveFactory(restrict) {
740
743
}
741
744
}
742
745
}
743
-
744
- function ngMessageDefaultDirectiveFactory ( restrict ) {
745
- return [ '$animate' , function ( $animate ) {
746
- return {
747
- restrict : 'AE' ,
748
- transclude : 'element' ,
749
- terminal : true ,
750
- require : '^^ngMessages' ,
751
- link : function ( scope , element , attrs , ngMessagesCtrl , $transclude ) {
752
- var commentNode = element [ 0 ] ;
753
-
754
- var currentElement , messageCtrl ;
755
- ngMessagesCtrl . register ( commentNode , messageCtrl = {
756
- attach : function ( ) {
757
- if ( ! currentElement ) {
758
- $transclude ( scope , function ( elm ) {
759
- $animate . enter ( elm , null , element ) ;
760
- currentElement = elm ;
761
-
762
- // in the event that the parent element is destroyed
763
- // by any other structural directive then it's time
764
- // to deregister the default message (boolean set to true)
765
- // from the controller
766
- currentElement . on ( '$destroy' , function ( ) {
767
- if ( currentElement ) {
768
- ngMessagesCtrl . deregister ( commentNode , true ) ;
769
- messageCtrl . detach ( ) ;
770
- }
771
- } ) ;
772
- } ) ;
773
- }
774
- } ,
775
- detach : function ( ) {
776
- if ( currentElement ) {
777
- var elm = currentElement ;
778
- currentElement = null ;
779
- $animate . leave ( elm ) ;
780
- }
781
- }
782
- } , true ) ; // boolean set to true to specify default message
783
- }
784
- } ;
785
- } ] ;
786
- }
0 commit comments