Tôi đã tạo thành phần img-pop có @Input()
liên kết thuộc tính src. Tôi đã tạo chỉ thị authSrc có tài sản @HostBinding()
src.Áp dụng chỉ thị thuộc tính vào thành phần trong Angular 4
@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;
}
}
Tôi có chỉ thị như thế này.
@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->";
}
}
tôi muốn kết hợp cả hai chức năng giống nhau.
<img-pop [authSrc]="/api/url/to/image"></img-pop>
để url cuộc gọi cuối cùng sẽ được/api/url/to/hình ảnh access_token = < --token ->
nhưng nó ném Can't bind to 'src' since it isn't a known property of 'img-pop'.
lỗi
Hãy sửa tôi nếu tôi sai với khái niệm.
Cảm ơn bạn.
vui lòng xem xét chấp nhận [câu trả lời của tôi] (https://stackoverflow.com/a/44099557/2545680) nếu nó giúp –