Angular lightbox: Can't bind to 'data-lightbox' since it isn't a known property of 'a'

我只是一个虾纸丫 提交于 2019-12-13 04:04:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!