我在创建自定义元素时遇到了困难,该元素将用于
<shimmy-dialog type="video" href="/test">Hi</shimmy-dialog>
种子元素将用href替换这段代码,单击href时应该弹出一个特定类型的对话框。
在我试图打开对话框之前,一切似乎都进行得很顺利。这是我得到错误的时候
未处理的拒绝TypeError:无法将属性'bindingContext‘设置为null,有时我确实会发现Aurelia错误有点简单。
我怀疑这与没有视图的元素有关。
代码如下
enum DialogType {
video = 1,
iframe
};
@inject(Bcp, DialogController)
export class ShimmyDialogModel {
private type : DialogType;
constructor(private bcp: Bcp, private controller : DialogController){
console.log("here");
}
async activate(state){
this.type = state['type'];
}
get isVideo() : boolean {
return this.type == DialogType.video;
}
get isIframe() : boolean {
return this.type == DialogType.iframe;
}
}
@noView
@processContent(false)
@customElement('shimmy-dialog')
@inject(Element, App, Bcp, DialogService)
export class ShimmyDialog {
@bindable public type : string;
@bindable public href;
@bindable public name;
private originalContent : string;
constructor(private element: Element, private app: App, private bcp: Bcp,
private dialogService: DialogService) {
this.originalContent = this.element.innerHTML;
}
bind() {
this.element.innerHTML = '<a href="#">' + this.originalContent + '</a>';
}
attached() {
let self = this;
this.type = this.element.getAttribute("type");
let dialogType = DialogType[this.type];
this.element.children[0].addEventListener("click", function(){
if(dialogType == DialogType.iframe) {
self.dialogService.open({ viewModel: ShimmyDialogModel, model: {'type' : dialogType}}).then(response => {
});
}
else if(dialogType == DialogType.video) {
self.dialogService.open({ viewModel: ShimmyDialogModel, model: {'type' : dialogType}}).then(response => {
});
}
return false;
});
}
async typeChanged(newValue) {
this.type = newValue;
}
async hrefChanged(newValue) {
this.href = newValue;
}
}
对话框的模板如下所示。
<template>
<require from="materialize-css/bin/materialize.css"></require>
<ai-dialog>
<ai-dialog-header>
</ai-dialog-header>
<ai-dialog-body>
<div if.bind="isVideo">
Video
</div>
<div if.bind="isIframe">
IFrame
</div>
</ai-dialog-body>
<ai-dialog-footer>
<button click.trigger="controller.cancel()">Close</button>
</ai-dialog-footer>
</ai-dialog>
</template>
谢谢你的帮助。
发布于 2016-11-04 09:11:21
我通过将类分离到它们自己的文件中来解决这个问题。Aurelia不喜欢在那里有两个导出类。
https://stackoverflow.com/questions/40399457
复制相似问题