Directives make our lives easier when you can reuse them without needing to read or edit the source code. Then we can forget how they work, and just remember what they do.
If you’re coming from a view-centric framework, like Backbone, you may be tempted to separate your application into view-like directive chunks. For example, if you want to display a list of users, you might create a directive that reads $scope.users and prints them all out:
<user-list/>The user-list directive works. I mean, look how DRY it is! However, contrast it withng-repeat, which handles only the repetition. Which one could be used in more places? What if you need to display users differently in two places?
Your new post is loading...