Closed djpate closed 2 years ago
Yes, you are right - its better to use Computed
. We could support them but it will make codes nasty and unreadable. The mahal frameworks wants you to write clean code as much as possible.
@ujjwalguptaofficial I think it might be a good idea to consider support expressions in the template. I expected them to work as well and was surprised to get some strange errors instead. Some expressions do actually seem to work in the template in fact. Things like {{1 + 1}}
will interpolate to 2 in the HTML as well as calls on objects: {{foo.bar}}
. On the other hand, a specific array item raises an error: {{tasks[0].message}}
(something about the square brackets fails to parse I think).
I know supporting expressions will probably lead to a bunch of edge-cases and complicated code but is it at least something you can consider as a future improvement or roadmap item possibly?
In the meanwhile, it's a good note to add to documentation in the future that only variables and methods from the class should be used in the template.
got your point. I will consider these in future roadmap or atleast better error message so that user knows what to do. Thank you very much for your suggestion.
@djpate i have fixed some of the issues, now should supports all type of expression. Let me know if you find any bug.
i have fixed in mahal-html-compiler
in version - 1.1.4. You need to update the mahal-html-compiler
.
Cool. Appreciate it.
Title
Not able to use expressions in the
if
directiveDescription
I'm not sure if that's supposed to work but I was expecting to be able to do
<span :if(tasks.length)>You have pending tasks</span>
or<span :if(tasks.length > 0)>You have pending tasks</span>
I have to write a computed method that does that in the class which is fine if that's by design but I wasn't sure.