динамически добавляем атрибут # в угловой элемент 6 - PullRequest
0 голосов
/ 19 ноября 2018

У меня есть следующий код в одном из моих шаблонов:

                 <ion-col text-center *ngFor="let shape of data.items[0].expandItems | slice:0:4; let i=index">
                  <a #btn{{shape.value}} class="item item-text-wrap notselected" (click)="toggleButtonShape(shape)">
                      <img src="{{shape.url}}">
                      <p>{{shape.title}}</p>
                  </a>
                 </ion-col>

И код в моем соответствующем файле .ts:

toggleButtonShape(shape) {
shape.isChecked = !shape.isChecked;
if(shape.value === 'BR') {
  if (shape.isChecked === true) {
    this.removeClass('notselected', this.btnBR);
  } else {
    this.addClass('notselected', this.btnBR);
  } 
} }


addClass(className?: string, element?: any) {
    this.renderer.addClass(element.nativeElement, className);
}


removeClass(className?: string, element?: any) {
    this.renderer.removeClass(element.nativeElement, className);
}

Проблема заключается в том, что при выполнении любой из вышеупомянутых функций параметр элемента равен undefined . Я объявил все @ViewChilds ().

...