I have created img-pop component which has @Input()
bind property src.
I have created authSrc directive which has @HostBinding()
property src.
@Component({
selector: 'img-pop',
template: `<img [src]="src"/>
<div *ngIf="isShow">
<----extra value----->
</div>`
})
export class ImgPopOverComponent implements OnInit {
@Input()
private src;
private isShow=false;
@HostListener('mouseenter') onMouseEnter() {
this.isShow= true;
}
@HostListener('mouseleave') onMouseLeave() {
this.isShow= false;
}
}
I have directive like this.
@Directive({ selector: '[authSrc]' })
export class AuthSrcDirective implements OnInit {
@HostBinding()
private src: string;
constructor(private element: ElementRef) { }
ngOnInit() { }
@Input()
set authSrc(src) {
this.src = src+"?access_token=<-token->";
}
}
i want to combine both functionality in one like.
<img-pop [authSrc]="/api/url/to/image"></img-pop>
so that final url call will be /api/url/to/image?access_token= <--token-->
but it throws Can't bind to 'src' since it isn't a known property of 'img-pop'.
error
Please correct me if i am wrong with conceptual.
Thank you.
According to this answer by the core contributor it's impossible to set direct properties of the component using
@HostBinding
.@HostBinding
always binds directly to the DOM. So this is by design. Here is the explanation:So, in your case, this is the possible solution:
For a more generic approach, see this.