Suppose I want to add maxlength attribute to abt-float-input as I know I should handle it as property in my custom element but I want to have it like Vue.
I rewrote one of my components with this feature in Vue.js.
Note that there is no @bindable value, or @bindable placeholder from <my-text-area/>, but we can still bind outside view model directly to inside <textarea/>.
I’ve added some comment explaining why things are what they are, hope that can help understand how it works.
When binding directly against a <textarea/>, Aurelia knows what property it should map attribute to: maxlength to maxLength, minlength to minLength etc… When binding through a layer like <my-text-area/>, it doesn’t have this knowledge. What you can do is to give Aurelia some more hint:
<my-text-area
max-length.bind="10">
Edit: Or you can use the same attribute map, that Aurelia use internally to map from standard attributes (all lower case, to their corresponding property in camel case), then you can do:
So cool, I think this should be a build-in feature in Aurelia vNext. It is very useful for creating new components. Helps us not reinvent the wheel and use existing attributes.
Because of this, In Aurelia-Toolbelt we had many problems until I saw the Vue.js technique and asked here.
Should I create an issue in Aurelia vNext repository?
Unfortunately does not exist any doc about Aurelia framework secrets!
Tbh, this is the first time I ever come across this, you helped me realized it’s possible. Thanks for this. I’ll probably write a small topic about it. Normally with Aurelia, you rarely ever need this.
You assigned au-bind to your custom element. As you can see I assigned it to target input in my-textbox template. It says assign all attributes of <my-textbox></my-textbox> to this input element.
I need to access and pass targetInstruction.expressions of parent (in here <my-textbox></my-textbox>) in to child (target input). for using attributes of parent for child too.
I think child component can not access to parent expressions.
Note that we are adding life cycle created to store reference to owning view of textarea because there is no way to walk up the scope from the custom aatribute. So the example works because the custom attribute assumes the custom elements that use it always have property named owningView pointing to that custom element owningView. This is only suitable for internal use.
We bind it to a variable but does not work however it works on your sample perfectly. I am not sure what is wrong in Typescript version. Here is the repository
You probaby didnt create created lifecycle in my textarea, also you need to store first parameter, known as owningView, in property owningView. For attributes without any binding (or plain attribute), i will need to have a look
This is a must have built in I would say moving forward with vNext. It needs extended to include attributes on the parent element that are not bound, but that is minimal.