组件中的 Angular2 : Uncaught (in promise): Quotes are not supported for evaluation!

标签 angular typescript

我有一个具有输入参数的组件:

import {Component,Input} from '@angular/core';

@Component({
    selector: 'comment' ,
    template: `    
        <div class="col-lg-6 col-md-6 col-xs-6 thumb">
            <div class="post-owner">
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                          <img class="media-object rounder" src=imageURI >
                        </a>
                    </div>
                </div>
            </div>
        </div>`
})

export class CommentCompoent{
    @Input() imageURI="";
}

在父组件中,我已经像这样向它传递了一个图像路径:

<comment [imageURI]='image_path'></comment>

问题是,当我运行它时,它会提示:

EXCEPTION: Error: Uncaught (in promise): Quotes are not supported for evaluation!

那我该怎么办呢?

更新:当我删除父组件中的 [imageURI]='image_path' 时它工作正常,它完美地显示了组件的其余部分

最佳答案

您应该将父组件中的 comment 标记更改为:

<comment [imageURI]="image_path"></comment>

分配模板绑定(bind)时不要使用单引号。仅使用它们来格式化字符串,如下所示:

<comment [imageURI]="'path/to/image.jpg'"></comment>

关于组件中的 Angular2 : Uncaught (in promise): Quotes are not supported for evaluation!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38855890/

相关文章:

typescript - protected 路由的 jest.mock express-jwt 中间件行为

angular - 更改月份后日期未更新

angular - 在 Angular HTML 输入变量中串联

angular - 摆脱 Angular Material 模态对话框周围的空白区域

javascript - Angular 是否具有 JQuery find() 的等价物

node.js - 发生未处理的异常 : Cannot find module 'C:\Users\...\node_modules\@angular-devkit\build-angular\src\dev-server'

reactjs - TypeScript Rest Props - 允许任何 Prop 或告诉组件它们将成为哪些 Prop

angular - 在 Angular 中包装 html 标签绑定(bind)的 UI 组件

angular - Ionic v4 菜单仅在 router-outlet 具有 main 属性时有效

angular - 模拟 http promise 服务时出现 `then is not a function` 错误