DEV Community

Discussion on: From Vue to Angular

Collapse
 
johncarroll profile image
John Carroll • Edited

Ah, well that's certainly intuitive! And that's definitely a better if/else syntax than what Angular has.

Again, not to invalidate the point of your article (but rather to explain why I think Angular is the way it is):

In Angular both ngIf and ngFor are simply standard structural directives which are shipped in CommonModule (and hence optional in an app). They rely on the same API that anyone can use to customize Angular. The limitations of that API (which is really pretty simple) are what create the wonky syntax. Personally, ngIf and ngFor (specifically) are so common that I think Angular would benefit if the framework gave them special treatment (which could improve the API for devs). Though I can see value in having complete consistency within the framework.

  • Edit I suppose making ngIf and ngFor special also might make them non-removable. And that would clash with Angular's goal of reducing the minimum framework size below 2kb (important for custom elements).

In Vue, is it possible to create a custom structural directive (or whatever Vue would call it) with similar functionality to v-if / v-else? e.g. is it possible to create a custom v-unless structural directive (which would also pair with v-else) for an app?

Thread Thread
 
codegram_user profile image
Codegram

Good to know, that's illuminating! :)

It is possible to create custom directives with Vue vuejs.org/v2/guide/custom-directiv... I never tried it, but since the hooks have access to the element el to manipulate the DOM, I guess you could create a simple v-unless that prevents it from rendering based on the binding.value. But it would be a standalone directive, I can't think of a way to pair it with an v-else or any other directive.