Aurelia 动态视图创建

Aurelia 动态视图创建,aurelia,Aurelia,我试图以最简单的方式获得一个简单的动态视图 import {inject, noView, ViewCompiler, ViewSlot} from 'aurelia-framework'; @noView @inject(ViewCompiler, ViewSlot) export class ButtonVM{ constructor(vc, vs){ this.viewCompiler = vc; this.viewSlot = vs;

我试图以最简单的方式获得一个简单的动态视图

import {inject, noView, ViewCompiler, ViewSlot} from 'aurelia-framework';

@noView
@inject(ViewCompiler, ViewSlot)
export class ButtonVM{

    constructor(vc, vs){

        this.viewCompiler = vc;
        this.viewSlot = vs;


        var viewFactory =  this.viewCompiler.compile('<button>Some button</button>');
import{inject,noView,ViewCompiler,ViewSlot}来自'aurelia framework';
@小说
@注入(ViewCompiler,ViewSlot)
导出类按钮{
构造函数(vc,vs){
this.viewCompiler=vc;
this.viewSlot=vs;
var viewFactory=this.viewCompiler.compile('Some button');

但是很明显我遗漏了一些东西,视图工厂应该能够创建一个视图,然后它应该被添加到一个viewslot

我在上面的代码中遗漏了什么

我应该提到的是,我在这篇文章中试图追随Rob的评论:

请参见Rob在同一页中更新的帖子

import{inject,noView,ViewCompiler,ViewSlot,Container,ViewResources}来自'aurelia framework';
@小说
@注入(ViewCompiler、ViewSlot、容器、ViewResources)
导出类测试{
构造函数(vc、vs、容器、资源){
this.viewCompiler=vc;
this.viewSlot=vs;
var viewFactory=this.viewCompiler.compile(“${title}”,参考资料);
var bindingContext={title:'Click Me'};
var view=viewFactory.create(容器、bindingContext);
this.viewSlot.add(视图);
this.viewSlot.attached();
}
}

答案很晚,但这可以通过使用aurelia提供的getViewStartegy方法轻松实现

export class Test {

 constructor(vc, vs, container, resources){
 }
 getViewStrategy() {
    return new InlineViewStrategy('<button>${title}</button>');
 }
}
导出类测试{
构造函数(vc、vs、容器、资源){
}
getViewStrategy(){
返回新的InlineViewStrategy(“${title}”);
}
}

是的,我注意到了,但不确定这是否足够。一旦我测试了它,我也会在这里发布结果。
export class Test {

 constructor(vc, vs, container, resources){
 }
 getViewStrategy() {
    return new InlineViewStrategy('<button>${title}</button>');
 }
}