How to create a custom template controller in Aurelia?


#1

In Angular, they have Structural Directives or Other Structural Directives so they can create custom if, switch,…

In one of the above examples, He created a custom loop as *appNgLoop.

AFAIK, we call them Template controller. Can we create custom template controller in Aurelia or Aurelia vNext too? If yes please guide me.


#2

Well actually if and repeat are just custom attributes in Aurelia. So yes it’s definitely doable. I’d recommend taking a look at their implementation linked above.


#3

Here is another simpler example https://github.com/bigopon/aurelia-portal-attribute/blob/master/src/portal.ts

It uses ViewSlot, View. For understanding purposes, I would suggest looking into if / else code, it’s way simpler than the repeat beast


#4

How sophisticated! Far from Aurelia way. I expected a simpler approach. :disappointed:


#5

For example?

POST MUST BE AT LEAST 20 CHARACTERS.


#6

Dear @davismj

I have no idea. just I thought it should be easier. At first glance, it seems hard.


#7

@HamedFathi you could view it in this angle.

We know software is built on top of stack of layers of abstraction. To make your code (the top layer) simple and intuitive, aurelia has to hide complexity beneath. Because to the end users of your app, who see your app as a black box, the total complexity is almost constant, no matter what tech stack you chose to build it.

Some layer has to absorb the complexity. Simple and intuition is relative to which layer you are looking at.