Angular (1.x) isnât my favorite tool. I love (and prefer) of Backbone, essentially because of Models and Collection, but I donât like Views, I prefer web components as Polymer or even better Riot (Riot is more about custom tags than web components, but functionally, itâs almost the same thing).
However, I do not always have a choice. As I do not master Angular, I looked for a long time how to use only the Angular directives for making custom tags. I wanted:
to use some kind of custom tags (with templating)
to work with Backbone Models and Collections
to forget Angular controllers, services, rootscope etc âŠ
And this is the sample of my experiments
My requirements are very simple, I want to display the content of a Backbone collection thanks a tag <humans></humans> :
So, Iâve created 2 directives:
Human directive (human.js): display a model
We have to bind a human model to the directive (scope : {human: '=model'}) and the display is updated when the model change.
Humans directive (humans.js): display models of the collection
The previous directive is nested in this directive (<human model="human"></human>) and we bind the model with each instance of the human directive when parsing the collection. The display is update when we add a model (or when a model change, but itâs only the nested item that is updated).
Updates of my html page
And thatâs all!
⊠Finally, Angular 1.x, itâs fun ;)