1
1
import { Component , ElementRef , Input , Output , EventEmitter , ViewChildren , QueryList , ViewChild , Renderer , HostListener , ViewEncapsulation } from '@angular/core' ;
2
+ import { DomSanitizationService } from '@angular/platform-browser' ;
2
3
3
4
import { Animation } from '../../animations/animation' ;
4
5
import { Transition , TransitionOptions } from '../../transitions/transition' ;
@@ -88,7 +89,7 @@ export class Picker extends ViewController {
88
89
template :
89
90
'<div *ngIf="col.prefix" class="picker-prefix" [style.width]="col.prefixWidth">{{col.prefix}}</div>' +
90
91
'<div class="picker-opts" #colEle [style.width]="col.optionsWidth">' +
91
- '<button *ngFor="let o of col.options; let i=index; " (click)="optClick($event, i)" type="button" category="picker-opt">' +
92
+ '<button *ngFor="let o of col.options; let i=index" [style.transform]="o._trans" [style.transitionDuration]="o._dur" [class.picker-opt-selected]="col.selectedIndex === i" [class.picker-opt-disabled]="o.disabled " (click)="optClick($event, i)" type="button" category="picker-opt">' +
92
93
'{{o.text}}' +
93
94
'</button>' +
94
95
'</div>' +
@@ -123,7 +124,7 @@ class PickerColumnCmp {
123
124
lastIndex : number ;
124
125
@Output ( ) change : EventEmitter < any > = new EventEmitter ( ) ;
125
126
126
- constructor ( config : Config ) {
127
+ constructor ( config : Config , private _sanitizer : DomSanitizationService ) {
127
128
this . rotateFactor = config . getNumber ( 'pickerRotateFactor' , 0 ) ;
128
129
}
129
130
@@ -342,15 +343,7 @@ class PickerColumnCmp {
342
343
343
344
this . col . selectedIndex = Math . max ( Math . abs ( Math . round ( y / this . optHeight ) ) , 0 ) ;
344
345
345
- let colElements = this . colEle . nativeElement . querySelectorAll ( '.picker-opt' ) ;
346
- if ( colElements . length !== this . col . options . length ) {
347
- // TODO: temporary until [style.transform] is fixed within ng2
348
- console . warn ( 'colElements.length!=this.col.options.length' ) ;
349
- return ;
350
- }
351
-
352
- for ( var i = 0 ; i < colElements . length ; i ++ ) {
353
- var ele : HTMLElement = colElements [ i ] ;
346
+ for ( var i = 0 ; i < this . col . options . length ; i ++ ) {
354
347
var opt = < any > this . col . options [ i ] ;
355
348
var optTop = ( i * this . optHeight ) ;
356
349
var optOffset = ( optTop + y ) ;
@@ -372,11 +365,8 @@ class PickerColumnCmp {
372
365
translateY = optOffset ;
373
366
}
374
367
375
- // TODO: setting by [style.transform]="o.transform" within the template is currently broke
376
- ele . style [ CSS . transform ] = `rotateX(${ rotateX } deg) translate3d(${ translateX } px,${ translateY } px,${ translateZ } px)` ;
377
- ele . style [ CSS . transitionDuration ] = ( duration > 0 ? duration + 'ms' : '' ) ;
378
- ele . classList [ this . col . selectedIndex === i ? 'add' : 'remove' ] ( 'picker-opt-selected' ) ;
379
- ele . classList [ opt . disabled ? 'add' : 'remove' ] ( 'picker-opt-disabled' ) ;
368
+ opt . _trans = this . _sanitizer . bypassSecurityTrustStyle ( `rotateX(${ rotateX } deg) translate3d(${ translateX } px,${ translateY } px,${ translateZ } px)` ) ;
369
+ opt . _dur = ( duration > 0 ? duration + 'ms' : '' ) ;
380
370
}
381
371
382
372
if ( saveY ) {
0 commit comments