99 Renderer ,
1010 AfterContentInit ,
1111} from '@angular/core' ;
12-
13-
12+ import { MdLine , MdLineSetter } from '../../core/line/line' ;
1413
1514@Component ( {
1615 moduleId : module . id ,
@@ -22,10 +21,6 @@ import {
2221} )
2322export class MdList { }
2423
25- /* Need directive for a ContentChildren query in list-item */
26- @Directive ( { selector : '[md-line]' } )
27- export class MdLine { }
28-
2924/* Need directive for a ContentChild query in list-item */
3025@Directive ( { selector : '[md-list-avatar]' } )
3126export class MdListAvatar { }
@@ -42,27 +37,25 @@ export class MdListAvatar {}
4237 encapsulation : ViewEncapsulation . None
4338} )
4439export class MdListItem implements AfterContentInit {
45- @ContentChildren ( MdLine ) _lines : QueryList < MdLine > ;
46-
4740 /** @internal */
4841 hasFocus : boolean = false ;
4942
50- /** TODO: internal */
51- ngAfterContentInit ( ) {
52- this . _setLineClass ( this . _lines . length ) ;
43+ _lineSetter : MdLineSetter ;
5344
54- this . _lines . changes . subscribe ( ( ) => {
55- this . _setLineClass ( this . _lines . length ) ;
56- } ) ;
57- }
45+ @ContentChildren ( MdLine ) _lines : QueryList < MdLine > ;
5846
5947 @ContentChild ( MdListAvatar )
6048 private set _hasAvatar ( avatar : MdListAvatar ) {
61- this . _setClass ( 'md-list-avatar' , avatar != null ) ;
49+ this . _renderer . setElementClass ( this . _element . nativeElement , 'md-list-avatar' , avatar != null ) ;
6250 }
6351
6452 constructor ( private _renderer : Renderer , private _element : ElementRef ) { }
6553
54+ /** TODO: internal */
55+ ngAfterContentInit ( ) {
56+ this . _lineSetter = new MdLineSetter ( this . _lines , this . _renderer , this . _element ) ;
57+ }
58+
6659 /** @internal */
6760 handleFocus ( ) {
6861 this . hasFocus = true ;
@@ -72,22 +65,6 @@ export class MdListItem implements AfterContentInit {
7265 handleBlur ( ) {
7366 this . hasFocus = false ;
7467 }
75-
76- private _setLineClass ( count : number ) : void {
77- this . _resetClasses ( ) ;
78- if ( count === 2 || count === 3 ) {
79- this . _setClass ( `md-${ count } -line` , true ) ;
80- }
81- }
82-
83- private _resetClasses ( ) : void {
84- this . _setClass ( 'md-2-line' , false ) ;
85- this . _setClass ( 'md-3-line' , false ) ;
86- }
87-
88- private _setClass ( className : string , bool : boolean ) : void {
89- this . _renderer . setElementClass ( this . _element . nativeElement , className , bool ) ;
90- }
9168}
9269
9370export const MD_LIST_DIRECTIVES = [ MdList , MdListItem , MdLine , MdListAvatar ] ;
0 commit comments