Aurelia Custom element with dialog

Glenn Pierce

I am having trouble with creating a custom element that will be used like

<shimmy-dialog type="video" href="/test">Hi</shimmy-dialog>

The custim element will replace this code with a href that when clicked should popup a dialog of a particular type.

Everything seems to work up until the point I try to open the dialog. This is when I get the error

Unhandled rejection TypeError: Cannot set property 'bindingContext' of null I do sometimes find the Aurelia errors a little cyptic.

I suspect it has something todo with the element not having a view.

The code is as follows

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;
  }
}

The template for the dialog is below.

<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>

Thanks for any help.

Glenn Pierce

I solved this by seperating the classes into their own files. Aurelia did no like having two export classes there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Custom Element Singletons in Aurelia

From Dev

Aurelia Multiple Properties in custom element

From Dev

Aurelia - render custom element by name

From Dev

Aurelia: Binding textContent of a custom element?

From Dev

Aurelia custom element with a table with a slot in it

From Dev

Aurelia Custom Element for modal form

From Dev

Binding to a Custom Element in a Template Part in Aurelia

From Dev

How to render razor view in aurelia custom element?

From Dev

Aurelia: validating form with reusable validatable custom element

From Dev

Aurelia: validating form with reusable validatable custom element

From Dev

Aurelia bindable attribute with HTML only custom element

From Dev

Jquery dialog, use custom html element as the title

From Dev

What is the difference between custom element and just an import using require in Aurelia

From Dev

Two-way binding between parent and child custom element in Aurelia

From Dev

Aurelia two-way binding in custom element not working

From Dev

How to set a parent property from within a custom element in Aurelia?

From Dev

How to implement bootstrap-datepicker as Aurelia custom element

From Dev

Aurelia - Inline definition of HTML-only custom element

From Dev

Aurelia binding hook on "nested" data update in custom element

From Dev

What is the difference between custom element and just an import using require in Aurelia

From Dev

Aurelia two-way binding in custom element not working

From Dev

Possible in Aurelia to wait for a promise in a custom element to complete before execution continues?

From Dev

How to reference specific elements in Aurelia custom element's <slot>?

From Dev

Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?

From Dev

How to include aurelia-dialog into bundle with Aurelia?

From Dev

How to use the aurelia-dialog plugin with Aurelia?

From Dev

Toggle paper-dialog which is in a custom element Polymer

From Dev

Custom element Polymer dialog size/position based on parent page

From Dev

Aurelia Dialog and Handling Button Events

Related Related

  1. 1

    Custom Element Singletons in Aurelia

  2. 2

    Aurelia Multiple Properties in custom element

  3. 3

    Aurelia - render custom element by name

  4. 4

    Aurelia: Binding textContent of a custom element?

  5. 5

    Aurelia custom element with a table with a slot in it

  6. 6

    Aurelia Custom Element for modal form

  7. 7

    Binding to a Custom Element in a Template Part in Aurelia

  8. 8

    How to render razor view in aurelia custom element?

  9. 9

    Aurelia: validating form with reusable validatable custom element

  10. 10

    Aurelia: validating form with reusable validatable custom element

  11. 11

    Aurelia bindable attribute with HTML only custom element

  12. 12

    Jquery dialog, use custom html element as the title

  13. 13

    What is the difference between custom element and just an import using require in Aurelia

  14. 14

    Two-way binding between parent and child custom element in Aurelia

  15. 15

    Aurelia two-way binding in custom element not working

  16. 16

    How to set a parent property from within a custom element in Aurelia?

  17. 17

    How to implement bootstrap-datepicker as Aurelia custom element

  18. 18

    Aurelia - Inline definition of HTML-only custom element

  19. 19

    Aurelia binding hook on "nested" data update in custom element

  20. 20

    What is the difference between custom element and just an import using require in Aurelia

  21. 21

    Aurelia two-way binding in custom element not working

  22. 22

    Possible in Aurelia to wait for a promise in a custom element to complete before execution continues?

  23. 23

    How to reference specific elements in Aurelia custom element's <slot>?

  24. 24

    Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?

  25. 25

    How to include aurelia-dialog into bundle with Aurelia?

  26. 26

    How to use the aurelia-dialog plugin with Aurelia?

  27. 27

    Toggle paper-dialog which is in a custom element Polymer

  28. 28

    Custom element Polymer dialog size/position based on parent page

  29. 29

    Aurelia Dialog and Handling Button Events

HotTag

Archive