AngularJS … Still?

When people say “AngularJS”, usually what they mean is the last stable version of Angular before version 2. Plenty of people have explained the differences, so I don’t think I need to belabor that point. Briefly, I’ll just say that Angular 2+ is built to use modern tools and techniques. Most important is that it’s built for use with modular JavaScript using webpack or tools like webpack to bundle the files. It’s typically written using TypeScript, which is novel, but that’s really beside the point. That’s not a new front end technology. It’s just a way to make JavaScript more verbose.

An important question to raise in the here and now is why anyone should still learn AngularJS. Like many people, I learned it a little back when it was new. There was a time when it was the best available tool. Since the introduction of better tools like Vue, I have largely forgotten what I used to know about AngularJS. But we still see AngularJS mentioned on job posts. The reason, most likely, is that these companies already have platforms written in AngularJS that need to be maintained.

That is a good enough reason for someone to learn AngularJS. If jobs are still hiring for it, then that’s reason enough. I started refreshing my memory by building some widgets in AngularJS. I put a few here: https://widgetwonk.azurewebsites.net/AngularJS. I do find myself torn on a few points. If I’m writing AngularJS, should I write as if its 2010? That is: in addition to using this antique technology, should I also write using 2010 JavaScript? What tools should I use for building my files?

Ultimately I decided to to mimic modern techniques as well as I could. The modern way to include a Vue component or an Angular component in a page is to define a tag and include it in the html like <my-custom-component></my-custom-component>. Then, when the script runs and the app is bootstrapped, this custom html element gets replaced with the appropriate template and controllers. In AngularJS, that means defining a custom “directive”.

Also, I didn’t want to have a lot of templates in the form of partial html files cluttering up my space, so I wrote my template is a large string using the back tic syntax, put it in a separate file called something like my-component-template.js and inclulded that with my bundled script. I used browserify to bundle the script.

It’s an unpleasant experience, and frankly I need to learn some parts of AngularJS brand new because back when I worked with it in 2010 I just wasn’t as good a programmer as I am now. There are things I didn’t do and didn’t know how to do back then, and I still don’t know how to do them in AngularJS even though I do them every time in Vue and React. Unit testing, for example. For that I guess I’ll have to learn AngularJS’s dependency injection system they crow about so often.

This raises another question. Should I review jQuery? I think maybe I draw the line at jQuery. I hated that even when it was new and necessary, and nowadays unless you write some kind of animation module I’m not sure you need jQuery for anything.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s