3 ms·
I do love having easy two-way data binding, too, certainly. To clarify: When you use a directive with an "isolate scope", you have to pass it parameters in you
by alanh 13y ago
I do love having easy two-way data binding, too, certainly.
To clarify: When you use a directive with an "isolate scope", you have to pass it parameters in your template, which means using arbitrary "HTML attributes" in ways that do not, in fact, have anything to do with HTML attributes. E.g.:
<my-directive model="myModel.foo" compact="true"></my-directive>
Is it plausible that HTML eventually defines a meaning for `model` and/or `compact` attributes? Did you just write illegal HTML? Yes. Is there already a way to do this in HTML? Yes, the `data-*` attribute namespace is free to use.
The whole dirty-checking thing requires an insane amount of CPU work, sometimes. Once you’re doing 15 or 20 AJAX requests, your browser may use 100% CPU for minutes (and that’s on desktop)! Why? We aren’t exactly sure. But I have bumped into other people at local JS meetups who have experienced the same thing. (Their solution? Give up and use Backbone. Ours? Load fewer things. I think it may also be viable to do all your network requests out of the Angular context to avoid a full dirty-check cycle on each `readyStateChange` event, but that’s not entirely straightforward, either, since we used Angular services to create our models, which know how to load their own dependencies… ack… it’s a mess.)
- sluukkonen 13y agoAngular supports data-attributes as well.
- evilduck 13y agoFYI, you can prefix all of Angular's HTML additions with data-ng-* attribute. <my-directive data-ng-model="myModel.foo" compact="true"></my-directive>
- alanh 13y agoThat’s true for `ng-model` but is it true for parameters passed in to directives?
- deleted 13y ago[deleted]
- marknutter 13y agoWhen you write directives you can define the attributes into which you pass parameters however you want, including making them HTML spec compliant.