1

I'm trying to create an Aurelia element inside of another element. I'm using the docking framework from phosphor and when I dynamically create a panel I want to add a component which I've build using Aurelia.

For example: I have a very simple logging component:

Logging.html

<template>
    <h1>Logging....</h1>
</template>

Logging.ts:

export class Logging {
    constructor() {
        console.log('Logging constructor')
    }
}

The component works as expected when I "just put it on the page".

Now inside of some method which creates the phosphor Widget I have something like this:

var widget = new Widget();
widget.title = "Got Logs?";
var contentElement = document.createElement('logging');
widget.node.appendChild(contentElement);
panel.insertBottom(widget);

This code, given a phosphor panel, creates a Widget, creates an element which looks like: <logging></logging> and appends it to the widget's inner node. The resulting "DOM" is correct but aurelia does not render the element.

I have also tried using the TemplatingEngine like so:

import { inject, TemplatingEngine } from 'aurelia-framework';

@inject(TemplatingEngine)
export class AureliaRoot {
    constructor(templatingEngine) { }

    attached() {
        var contentElement = document.createElement("logging"),
            el = document.getElementById("my-element");
        el.appendChild(contentElement);
        templatingEngine.enhance({element: el, bindingContext: {}});
    }
}

But this doesn't seem to work, although I doubt I'm using it right and I think I might need to use compile, really not sure there.

Any insights would be appreciated.

4

1 回答 1

1

很抱歉,我无法完全回答,但我相信您需要使用 Aurelia ViewCompiler 来编译生成的 HTML 片段,以便 Aurelia 解析它们。

尝试查看以下链接以获取更多信息:如何使用 ViewCompiler 手动编译部分 DOM?

于 2016-07-04T14:23:25.227 回答