Aurelia - render custom element by name

Alexander Mikhalchenko

Suppose we have a custom element that renders a list of something. It is a selector element, so it does not atter how this something is rendered.

The problem is that this something is quite generic and there are custom elements to actually render it. For example, for countries we add a flag image, for general elements - a fontawesome icon, reputation for users, etc.

What I would like to have

And now I would like to pass the name of the custom element I want to render something with. So instead of this

<selector data.one-way="options" selected.two-way="selected"></selector>

Have something like

<selector element="country" data.one-way="options" selected.two-way="selected"></selector>

And in the selector I would like to have

<${element} content.one-way="el" repeat.for="el of data"></${element}>

What I get

Unfortunately, the code above renders as htmlescaped

<country content.one-way="el" repeat.for="el of data"></country>

So,

Is there a more or less clean way to achieve that? Basically I would like to pass the specify custom elements I want to render in my selector custom element. This post and the answer there have nothing to do with my question.

Using compose as described here... well, it is an option, but I would like to have different custom elements and a slightly different logic in CustomElement js files.

Thanks!

UPD

Well, there's an obvious way to do that by just adding something like a switch statement in the view

<country ... if.bind="el.type === 'country'"></country>
<phone ... if.bind="el.type === 'phone'"></phone>
<user ... if.bind="el.type === 'user'"></user>

But that would make the selector element dependent on country, user etc. So I would not like that.

Egor Malkevich

I found couple possible solutions, they may seems more complicated then compose.

@bindable({
  name:'myProperty', //name of the property on the class
  attribute:'my-property', //name of the attribute in HTML
  changeHandler:'myPropertyChanged', //name of the method to invoke when the property changes
  defaultBindingMode: ONE_WAY, //default binding mode used with the .bind command
  defaultValue: undefined //default value of the property, if not bound or set in HTML
})

You can find more details there http://www.sitepoint.com/extending-html-aurelia-io-way/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to render razor view in aurelia custom element?

From Dev

Custom Element Singletons in Aurelia

From Dev

Aurelia Custom element with dialog

From Dev

How do get Aurelia to render my view after dynamically adding a custom element to the DOM?

From Dev

Aurelia Multiple Properties in custom element

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

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

How to render shadow DOM in a polymer custom element

From Dev

Custom directive to conditionally render wrapper element

From Dev

Custom directive to conditionally render wrapper element

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

Is it possible to style custom elements with dashes in the element name?

From Dev

Use native node name for a Polymer custom element?

Related Related

  1. 1

    How to render razor view in aurelia custom element?

  2. 2

    Custom Element Singletons in Aurelia

  3. 3

    Aurelia Custom element with dialog

  4. 4

    How do get Aurelia to render my view after dynamically adding a custom element to the DOM?

  5. 5

    Aurelia Multiple Properties in custom element

  6. 6

    Aurelia: Binding textContent of a custom element?

  7. 7

    Aurelia custom element with a table with a slot in it

  8. 8

    Aurelia Custom Element for modal form

  9. 9

    Binding to a Custom Element in a Template Part in Aurelia

  10. 10

    Aurelia: validating form with reusable validatable custom element

  11. 11

    Aurelia: validating form with reusable validatable custom element

  12. 12

    Aurelia bindable attribute with HTML only custom element

  13. 13

    How to render shadow DOM in a polymer custom element

  14. 14

    Custom directive to conditionally render wrapper element

  15. 15

    Custom directive to conditionally render wrapper element

  16. 16

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

  17. 17

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

  18. 18

    Aurelia two-way binding in custom element not working

  19. 19

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

  20. 20

    How to implement bootstrap-datepicker as Aurelia custom element

  21. 21

    Aurelia - Inline definition of HTML-only custom element

  22. 22

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

  23. 23

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

  24. 24

    Aurelia two-way binding in custom element not working

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

    Is it possible to style custom elements with dashes in the element name?

  29. 29

    Use native node name for a Polymer custom element?

HotTag

Archive