4 ms·
Every time I see someone explaining the Angular API I cringe because it seems like an API that has no respect for the user actually forced to learn it. Everythi
by ianstormtaylor 13y ago
Every time I see someone explaining the Angular API I cringe because it seems like an API that has no respect for the user actually forced to learn it. Everything seems so hostile. For example:
restrict: 'E'
Good luck knowing what that does at first glance. Instead why couldn't it have been simply called:
type: 'element'
Or another one, surely the default for creating new custom elements would be to always replace the element, so we shouldn't have to manually set:
replace: true
But we do because not all directives default to replacement, so maybe they thought it would get confusing if some defaulted to it. Instead they probably should have realized that the problem wasn't with the default for replacement, it was that everything was shoe-horned into a "directive". Why not have an easy shortcut for create elements vs. creating events or attributes...
app.element('button', ...
app.attribute('toggle', ...
app.event('scroll', ...
And then you can have sensible defaults for each one without the user getting extremely confused. I would absolutely expect elements to replace by default.
I'm sure this is an oversimplification, but surely there have to be less implementor-hostile ways to write these features. For example, even after reading the article I still have no idea what setting this on an attribute does:
scope: {
toggle: '='
}
That's ridiculous. I don't think there are enough designers on the Angular team.
- mortalapeman 13y agoDirectives are a DSL for creating new behavior using HTML. Once you learn the language, the symbols make sense and directives are easy to read. I think you are confusing "intuitive" with "familiar". Since you are not familiar with directives, you do not find them intuitive.
- lucisferre 13y agoI think there is still a fair point. I'm quite familiar with AngularJS and writing quite advanced directives and I would agree some of the APIs are not as user-friendly as they should ideally be. Couple that with limited documentation and guidance and you have quite a steep learning experience. Bottom line, things could be better.
- mortalapeman 13y agoI partially agree, directives are not easy to learn, and there is not enough good documentation or literature on how to write them well. However, I have found the api to be very expressive , concise, and flexible once mastered. I can't say the same for most real languages I work with everyday.
- robmcm 13y agoscope: { toggle: '=' } That's a joke, with minification these days what's the point in being so concise and confusing. Bad from an API design point of view and bad that the tutorial felt it didn't need some explination.
- KurtMueller 13y agoThis tutorial assumes you already familiar with the basics of Angular's directives and focuses on the actual design of directives you wish to write.
- robmcm 13y agoI think you should assume that people may have a conceptual knowledge but not a working knowledge. If they had a working knowledge then your tutorial would be obsolete IMO. Other than that confusion I found it enjoyable. FYI some of your examples are returning 404's
- embwbam 13y agoThanks, fixed!