Notes on Angular Getting Started Shopping App

Wading into a new domain always means learning a new vocabulary as well. The first thing I read was Introduction to Angular Concepts, knowing full well not all of it would make sense until later. The most valuable thing it taught me is that certain generic-sounding words actually have specific meanings within an Angular context, which is an important lesson to learn while reading documentation. In this case, I have to be careful when coming across words like “modules”, “components”, and “services”.

Angular’s “Getting Started” section starts out with a “Try It” walk through building a sample Angular application. It is a mock shopping app with a product list, a shopping cart, and checkout UI. They do the usual web app things like creating forms (got to have those forms) and communicate over HTTP. Following along with this sample, I got to see the concepts of “components” and “services” put into practice. I’m still a little fuzzy on “modules”, though. I believe it is because modules don’t really come into their own until we have a much larger project. At which point it makes sense to group lots of components into modules, something that would not be necessary in a small sample tutorial.

I also got to see the good and bad sides of using TypeScript. The good news is that some mistakes will trigger compile-time errors for me to fix before proceeding. I find this a vast and compelling improvement over JavaScript standard operating procedure of watching things going awry at runtime and trying to debug what went wrong. The bad news is that it’ll take some experience before I can understand what those error messages are trying to tell me. Here’s one example of an error message that I found bewildering. It wasn’t immediately obvious to me that I used too many curly braces, three instead of two.

Template parse errors:
Parser Error: Missing expected : at column 9 in [ {{{product.name}}} ] in ng:///AppModule/ProductListComponent.html@3:6 ("

<div *ngFor="let product of products">
<h3>[ERROR ->]
{{{product.name}}}
</h3>
"): ng:///AppModule/ProductListComponent.html@3:6
Parser Error: Unexpected end of expression: {{{product.name}}} at the end of the expression [ {{{product.name}}} ]

Going through the exercise I learned that an Angular component typically associates the three parts of web development (HTML, CSS, JavaScript) into a functional unit. The JavaScript file defines the component class. The HTML is modified with Angular-specific annotations and called the component template. And the component style sheet was a pleasant surprise, since I had struggled with how to best organize my style sheet files in earlier projects. Hopefully Angular components will make it easier.

I felt it was an effective introduction, giving a quick tour of major components of Angular and giving me enough of a vague idea of what’s going on, enough to proceed further and learn more. But before I go deeper into Angular, a little detour to look at the infrastructure behind this “Try It” walkthrough.

Siren Call of Angular Material

I started thinking about doing another web technology project because I thought it might be good to have the option of building my own custom Node-RED Dashboard widgets. But during my research of study prerequisites I started reading about Angular. The more I read, the more I think it’s worth a closer look. I was enticed by the following:

  • It is a web technology of the SPA (single page application) era, moving more processing to the web browser and reducing load on the web server. Google has obvious incentive to reduce their server load, but it also means SPAs can be compiled down to static content and hosted on any web server. For hobbyist projects, this drops the minimum hardware requirement from a Raspberry Pi (to run something like Ruby on Rails) down to an ESP32 (static web server).
  • Angular is built on TypeScript, which adds compile-time type checking capabilities to JavaScript. Potentially eliminating a lot of JavaScript runtime failures that have frustrated me in the past.
  • And last but definitely not least: Angular Material components

Angular Materials is now my primary motivation, displacing Node-RED Dashboard. I’ve been fascinated by Google’s Material Design ever since the concept was launched. This is not a surprise to anyone who’ve seen my web technology projects. The SGVHAK rover UI was built on an early version of Materialize CSS. It gave me a Material Design look but with usage semantics somewhat resembling Bootstrap. My LRWave project was written using completely different set of tools, but it also picked up a Material Design style by the use of Material Design Components (MDC) for Web.

So the siren song call of Material Design has pulled me in yet again, this time to Angular and the promise of being able to build UI for projects that can be hosted anywhere… from static servers like an ESP32 or GitHub Pages, to full fledged web server running on a Raspberry Pi, to desktop applications via ElectronJS.

It all sounds very attractive for a tool to add to my toolbox, so I’ll start investing some time into learning Angular.

Diving Into Web Technologies Again

Digging into an obscure button was fun, but (sadly?) not the main focus of this blog, which is for me to write down notes about my projects and technology explorations. If anyone finds the information useful, that’s just icing on the cake.

This time around, getting back to “work” puts focus on software development. My learning experience with the Node-RED Dashboard taught me it was very easy to get a functional browser-based UI up and running giving users like myself a fantastic way to build out ideas. But with ease of use comes the usual trade-off of limited control. The people behind Node-RED Dashboard is aware of this, providing anyone who is unsatisfied with the default tools an entry point to add custom dashboard widgets. Unfortunately, the learning curve climbs sharply upwards for me since I have little experience with many of the underlying technologies. If I want to explore that world, I have to weigh the following points:

  1. No experience with AngularJS (a.k.a Angular v1) which is the foundation of Node-RED Dashboard.
  2. No experience with Angular (a.k.a. Angular v2+) which is an incompatible but currently-maintained replacement.
  3. No experience with creating reusable JavaScript modules or the convention around creating packages.
  4. Only basic skills with HTML, CSS, and JavaScript.

This list is sorted roughly in the order of most- to least-specific to my original motivation of creating custom Node-RED widgets. With such a list it usually makes the most sense to start at the top (focus on the motivating goal) or start at the bottom (build a solid foundation.)

For the purposes of foundation building, I’ve tackled a few HTML/CSS/JavaScript projects but nothing that really stuck with me for long term development. An early example was the web based UI for SGVHAK rover, which eventually became my default control scheme for Sawppy rover as well. Updating that UI has been on my to-do list ever since, and I have yet to get back to it. I later explored a different set of web development tools with my LRWave project, but again that had been set aside after v1.0 was complete. Given this track record, I’m not sure retreading the same grounds will give better results.

So what about the other side? Start with AngularJS? I was ready to do so because of Node-RED Dashboard, but most of my motivation evaporated when I learned AngularJS has been abandoned. If I want to learn something that’ll be useful beyond Node-RED dashboards, I should learn its successor Angular instead.

But there was also a more vain attraction to Angular that called to me…