Trying to work with angular 5 and faced with a challenge: how can I pass a JSON array to a custom directive?
Here's my current code:
product.ts
products=[{"laptop":"dell", id:1}, {"laptop":"lenovo", id:2}];
product.html
<div product-data="{{data}}" *ngFor="let data of products"></div>
product-data.ts
@Directive({
selector: '[product-data]'
})
export class ProductDetailsDirective {
@Input('template-thumbnail') productSelected:any;
ngAfterViewInit() {
console.log(this.productSelected)
}
}
Upon logging the productSelected, I'm seeing a string [object Object] instead of an array.
Any suggestions or guidance on this issue would be highly appreciated.