I'm new with angular directive so I had created a directive as follows:
import { Directive, ElementRef, Input, Output } from '@angular/core';
@Directive({
selector: "[bonusCard]"
})
export class BonusCard {
@Input() bonus: string;
@Input() amount: string;
@Input() isSeleted: string;
constructor(private el: ElementRef){
el.nativeElement.innerHTML = this.getTemplate()
}
getTemplate(){
return ''+
'<div>'+
'<div class="bonus">'+this.bonus+'</div>'+
'<div class="amount">'+this.amount+'</div>'+
'<div class="radio '+(this.isSeleted?'is_seleted':'')+'"></div>'+
'</div>' +
'';
}
}
I'm using this directive in template as follows:
<div class="column col-3" *ngFor="let b of bonusJson;let i = index" bonusCard [bonus]="b.bonus" [amount]="b.amount" [isSeleted]="i==activeBonus"></div>
where variable are defined as below:
bonusJson = [{
bonus:1500,
amount:2000
},{
bonus:1000,
amount:1000
},{
bonus:500,
amount:500
},{
bonus:0,
amount:100
}];
activeBonus = 0;
But view is not rendering correctly it is showing undefind in view as below.
