无法从 @inlineView 访问 VM 属性

pow*_*uoy 1 aurelia

我在 Aurelia 中创建了一个简单的自定义元素,它使用了一个@inlineView()(因为视图很小)但是当我尝试从我的内联视图访问我的 VM 属性之一时,我只是得到“属性未定义”;

import {inlineView} from 'aurelia-framework';

@inlineView(`<template><h1>${title}</h1></template>`)
export class MyCustomElement {
    constructor () {
        this.title = 'Hello, World!';
    }
}
Run Code Online (Sandbox Code Playgroud)

@bindable也会发生;

export class MyCustomElement {
    @bindable title = 'Hello, World!';

    constructor () {
    }
}
Run Code Online (Sandbox Code Playgroud)

Fab*_*Luz 5

<template><h1>${title}</h1></template>被解释时,解释器会尝试插入title尚不存在的变量。尝试这个:

@inlineView(`<template><h1 innerHTML.bind="title"></h1></template>`)
Run Code Online (Sandbox Code Playgroud)

或者更简单:

@inlineView('<template><h1>${title}</h1></template>') // without accents
Run Code Online (Sandbox Code Playgroud)