在aurelia中编写html文件

时间:2016-10-12 00:23:09

标签: aurelia

我希望达到类似" include"在android中,但在aurelia中:

如何在我的视图中注入普通的html文件内容,在父视图中评估绑定,而不使用自定义元素? 绑定innerhtml是不够的,因为根据文档,绕过了绑定表达式。

1 个答案:

答案 0 :(得分:2)

正如Ashley所说,使用<compose view="./your-view.html"></compose>元素将与现有的HTML文件一起使用,它将继承父上下文。

如果您想动态地(从文件,数据库或以编程方式构建)组合HTML,那么使用ViewCompiler将为您提供最佳性能和灵活性,因为这是一层小于{{1与aurelia如何在内部构建自定义元素进行比较。

我在这里给出了一个不同(但相关)问题的类似答案:

Aurelia dynamic binding

您使用compose插件将HTML文件作为文本加载到变量中,然后将其传递给ViewCompiler。我有一个自定义元素,就性能而言,可能并不比text好,但它确实允许在使用原始html作为输入时进行更多控制,并且您可以针对您的情况进行自己的性能优化根据需要:

compose

观点:

import * as markup from "text!./your-element.html";

export class SomeViewModel {
    constructor() {
        this.markup = markup;
    }
}

为了完整起见,这里是我将ViewCompiler封装在的自定义元素:

<template>
    <dynamic-html html.bind="markup"></dynamic-html>
</template>
相关问题