Creating a dynamic view
I am trying to make a simple dynamic view in the simplest way possible.
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>');
but apparantly I am missing something, the factory view should be able to create the view and then it should be added to the viewport?
What am I missing in the above code?
I should mention that I tried to follow Rob's comments on this thread: https://github.com/aurelia/templating/issues/35
+3
source to share
2 answers
See Rob's updated post on the same thread .
import {inject, noView, ViewCompiler, ViewSlot, Container, ViewResources} from 'aurelia-framework';
@noView
@inject(ViewCompiler, ViewSlot, Container, ViewResources)
export class Test {
constructor(vc, vs, container, resources){
this.viewCompiler = vc;
this.viewSlot = vs;
var viewFactory = this.viewCompiler.compile('<button>${title}</button>', resources);
var bindingContext = { title:'Click Me'};
var view = viewFactory.create(container, bindingContext);
this.viewSlot.add(view);
this.viewSlot.attached();
}
}
+3
source to share