绑定表达式不能在表达式ANGULAR 7的末尾包含链接表达式

Abd*_*him 1 angular angular6 angular7

在npm run build时间显示的错误

    Parser Error: Binding expression cannot contain chained expression at the end of the expression [getImageUrl(image, true);] in E:/Work/JamesJ/Pixie/pixie-image-editor/source/src/app/image-editor-ui/panels/open-sample-image-panel/open-sample-image-panel.component.html@34:9 ("

<div class="samples" *ngIf="sampleImages" >
    <img [ERROR ->][src]="getImageUrl(image, true);" *ngFor="let image of sampleImages" (click)="openSampleImage(image)"")
: Parser Error: Binding expression cannot contain chained expression at the end of the expression [getImageUrl(image, true);] in E:/Work/JamesJ/Pixie/pixie-image-editor/source/src/app/image-editor-ui/panels/open-sample-image-panel/open-sample-image-panel.component.html@34:9 ("

<div class="samples" *ngIf="sampleImages" >
    <img [src]="getImageUrl(image, true);" [ERROR ->]*ngFor="let image of sampleImages" (click)="openSampleImage(image)">
</div>")
: Parser Error: Binding expression cannot contain chained expression at the end of the expression [getImageUrl(image, true);] in E:/Work/JamesJ/Pixie/pixie-image-editor/source/src/app/image-editor-ui/panels/open-sample-image-panel/open-sample-image-panel.component.html@34:9 ("ngIf="sampleImages" >
    <img [src]="getImageUrl(image, true);" *ngFor="let image of sampleImages" [ERROR ->](click)="openSampleImage(image)">
</div>")
Run Code Online (Sandbox Code Playgroud)

html代码是

    <div class="samples" *ngIf="sampleImages" >
    <img [src]="getImageUrl(image, true);" *ngFor="let image of sampleImages" (click)="openSampleImage(image)">
</div>
Run Code Online (Sandbox Code Playgroud)

组件代码为:

public getImageUrl(image: SampleImage, useThumbnail = false) : string {
    const url = (image.thumbnail && useThumbnail) ? image.thumbnail : image.url;
    // prefix relative link with base url, if needed
    if (url.indexOf('//') === -1) {
        return this.config.getAssetUrl(url);
    } else {
        return url;
    }
}
Run Code Online (Sandbox Code Playgroud)

Dán*_*rta 5

删除分号:

    <img [src]="getImageUrl(image, true)" ...>
Run Code Online (Sandbox Code Playgroud)

  • @Vikas - 寻找“解析器错误:绑定表达式不能包含链式表达式”的人会找到这个答案并得到解决方案。 (7认同)
  • @AbdurRahim 我很高兴。原因正是您在错误消息中得到的:您只能将一个表达式绑定到一个属性。原因主要是这就是 angular 的工作原理。使用分号,您可以关闭表达式,因此它不会解析表达式的返回值。另一方面,对于事件,你可以这样做:`&lt;div (click)="someCallback(); console.log('hi')"...` (4认同)
  • 为什么这么@Vikas?这是对他问题的回答。对于和他犯过同样错误的人来说,这很有用。 (2认同)