【问题标题】:Binding expression cannot contain chained expression at the end of the expression ANGULAR 7绑定表达式不能在表达式 ANGULAR 7 的末尾包含链式表达式
【发布时间】:2019-05-21 22:45:05
【问题描述】:

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>")

html代码是

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

组件代码为:

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;
    }
}

【问题讨论】:

  • [src]="getImageUrl(image, true)"去掉分号
  • 你有没有试过去掉这里的分号? [src]="getImageUrl(image, true);"

标签: angular angular6 angular7


【解决方案1】:

去掉分号:

    <img [src]="getImageUrl(image, true)" ...>

【讨论】:

  • 也许应该是评论而不是答案,它对社区有什么用处?
  • @Vikas - 寻找“解析器错误:绑定表达式不能包含链式表达式”的人会找到这个答案并得到解决方案。
  • 为什么是@Vikas?这是对他问题的回答。这对任何和他犯过同样错误的人都有用。
  • @DánielBarta 你能解释一下为什么在分号后面加分号是错误的吗?其实我也不知道,所以才问。是的,它的工作原理。
  • @AbdurRahim 我很高兴。原因正是您在错误消息中得到的:您只能将一个表达式绑定到一个属性。原因主要是角度是这样工作的。使用分号,您可以关闭表达式,因此它不会解析表达式的返回值。另一方面,对于事件,您可以这样做:&lt;div (click)="someCallback(); console.log('hi')"...
猜你喜欢
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多