问题
I read Angular. It says if you want to bind a property it should be wrapped with []. So here what I did, But I am getting error. Any idea what am I doing wrong?
My requirement is to have the value of data-lightbox is what I am setting/sending from another component(parent component)
image-display.component.ts
@Component({
selector: 'app-image-display',
templateUrl: './image-display.component.html',
styleUrls: ['./image.component.css']
})
export class ImageDisplayComponent implements OnInit {
@ViewChild('inspImage') image: ElementRef
@Input() inspection: LineSideInspection
inpsectionId: number;
santizer: DomSanitizer
constructor(private imageService: ImageDisplayService, private sanitizer: DomSanitizer) {}
ngOnInit() {
this.getMyImage('/getimage/' + this.inspection.id );
this.inpsectionId = this.inspection.id;
}
}
image-display.component.html
<a [href]="sanitize(inspImage.src)" [data-lightbox]="inspectionId" data-title="inspect.inspectionDescription">
<img #inspImage width="110px" height="95px">
</a>
package.json:
"lightbox2": "^2.10.0",
回答1:
Try using -
<a [href]="sanitize(inspImage.src)" [attr.data-lightbox]="inspectionId" data-title="inspect.inspectionDescription">
<img #inspImage width="110px" height="95px">
</a>
回答2:
I found a way of showing title in the lightbox. Here is what I did:
In component.ts, I declared a string variable and assigned value in init method, then in html, I put that variable inside double brackets.
html:
<a [href]="sanitize(inspImage.src)" [data-lightbox]="inspectionId" data-title="{{inspectionName}}">
TS:
public inspectionName: string;
ngOnInit(){
this.inspectionName = this.inspection.inspectionName;
}
来源:https://stackoverflow.com/questions/50411836/angular-lightbox-cant-bind-to-data-lightbox-since-it-isnt-a-known-property