javascript - 如何在 Angular2 的模板指令中使用 html?

标签 javascript html angular typescript onclick

目前我想在模板中有一个可点击的 anchor 标记来显示消息。但是,在运行时,我不断收到此错误。

未捕获的 ReferenceError:未定义显示

我的代码如下:

prepareKendoGrid(searchresults:any[]) {
    console.log(this.searchresults);

    this.adhocSearchKendoGrid = {
        sortable: true,
        columns: [{
            field: "filename",
            title: " ",
            width: 50,
            template: "#if(filetype == 'xml') {#<i style='margin-left:10px' class='fa fa-file-code-o fa-1x'></i>#} else if(filetype == 'doc') {#<i style='margin-left:10px' class='fa fa-file-word-o fa-1x'></i>#} else if(filetype == 'pdf') {#<i style='margin-left:10px' class='fa fa-file-pdf-o fa-1x'></i>#}else if(filetype == 'txt') {#<i style='margin-left:10px' class='fa fa-file-text-o fa-1x'></i>#}#"
        },
        {
            field: "filename",
            title: "File Name",
            width: 200
        },
        {
            field: "content",
            title: "Content"
        },
        {
            field: "start_time",
            title: "Conversation Date",
            width: 200
        },
        {
            field: "attachments.count",
            title: "Attachments",
            width: 100,
            template: "<a style='margin-right:10px' (click)='display()'><i class='fa fa-paperclip fa-fw'></i></a>#: attachments.count #"
        }],
        dataSource: searchresults
    };

    let cst = new CSTGridComponent();
    cst.createGrid(this.adhocSearchKendoGridId,this.adhocSearchKendoGrid);
}

display() {

    console.log('ok');
    }
}

最佳答案

应该是

(click)='display()'

另见

关于javascript - 如何在 Angular2 的模板指令中使用 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40213320/

相关文章:

javascript - 带有对象数组的多重选择和 v-model

javascript - 二维数组中的 "cannot read property 0 of undefined"

javascript - 轮播 - 将文本与 slider 中的图像相关联

angular - 在 RXJS Tap 操作符内部时,Console.Log 不会执行

javascript - Jasmine 测试,addEventListener

javascript - 在浏览器中播放原始 h264 直播流

html - 在输入元素下方显示输入标签

php - 如何在没有原始 fla 文件的情况下制作 swf 链接?

angular - 在 Mat-Select 中隐藏选定的选项

php - Angular 5 - 尽管(Set-Cookie)在响应 header 中,但已设置 Cookie