我有一個組件,我想通過屬性將某些數據傳遞給ngFor
中的子組件。基於屬性,我想最終設計這些子組件。如何設置具有屬性的角度4組件?
代碼
testimonials.component.html - (Parent component)
<ng-template ngFor let-person="$implicit" [ngForOf]="peopleAsPreviousCurrentAndNextTriplets" let-i=index let-last=last>
<app-card
[prevCard] ="last ? person.previous : null"
[currentCard] ="last ? person.current : null"
[nextCard] ="last ? person.next : null"
></app-card>
</ng-template>
card.component.ts - (Child component)
import {Component, Input, ViewChild} from '@angular/core';
import {Person} from '../testimonials/person';
@Component({
selector: 'app-card',
templateUrl: './card.component.html',
styleUrls: ['./card.component.scss']
})
export class CardComponent {
@Input() decrement: Number;
@Input() defaultDiff: Number;
@Input() currentCard: Person;
@Input() prevCard: Person;
@Input() nextCard: Person;
@ViewChild('card') card;
constructor() { }
}
而且我想風格<app-card>
與[currentCard]
屬性。
child.component.sass
:host {
&[currentCard] {
.testimonials__card-container {
background-color: black;
}
}
}
不知道爲什麼沒有被應用上述風格。
請幫忙。
感謝
編輯
下面就以我的形象化上漲卡:
'[currentCard]'是*綁定*,它實際上並不適用該屬性。嘗試在條件上將元素放在元素上。 – jonrsharpe
你的問題是我每天服用的SO。這次真是萬分感謝。 – Moshe
大聲笑,林不知道應該爲此感到高興。道歉,如果我給你造成任何困擾@Moshe – James