Learning resources

Tutorials

Misc StackOverflow questions

SCSS

Using CSS classes to style the parent div of a component

Udemy - Max Schwarzmüller - Master Angular: The Complete Course

Summary of key ideas from the course I want to remember

Section 2: The Basics

Section 1: Getting Started

Section 2: The Basics

How an Angular app gets loaded and started
Components are important!
Creating a new component
Understanding the role of AppModule and component declaration
Using Custom Components
Creating Components with the CLI & Nesting Components
Working with Component Templates
Working with Component Styles
Fully Understanding the Component Selector
What is Databinding?
String Interpolation
  1. Use the syntax {{ expression }} to do string interpolation in a template.

  2. The expression just needs to resolve to a string or something that can be converted to a string (like a number).

  3. When defining custom methods in a component class, you just define them at the top level of the class. You don’t nest them in a “methods” object or something.

Property Binding
  1. He spends a fair amount of time showing himself creating a setTimeOut function in the constructor to update a variable, which isn’t relevant to the topic at hand.

  2. To bind the value of a property to an expression, wrap the property in square brackets like this:

    <button [disabled]="!allowNewServer"></button>
  3. So it's like v-bind: or : in Vue:

    <button :disabled="!allowNewServer"></button>
Property Binding vs String Interpolation
  1. Use string interpolation when you want to display some string in the template, use property binding when you want to control the value of a property using an expression.

  2. Remember not to use curly braces where you’re supposed to put an expression.

Event Binding
  1. He likes to name his component functions that called by some event starting with “on”, like onEventCreated

  2. Angular uses parentheses to indicate events:

    <button (click)="onEventCreated()"></button>
  3. So it’s the equivalent of @ in Vue: <button @click="onEventCreated">

    1. But you need to include the parentheses when calling a function in Angular.

Bindable Properties and Events
  1. To see what properties and events an HTML element offers, use console.log() on the element.

  2. The MDN docs also have lists of the properties and events available for HTML elements; search Google and you should find the relevant docs.

Passing and Using Data with Event Binding
  1. We can capture event data by passing the $event object to the function we call.

  2. The target attribute of the event object is the HTML element.

  3. The value attribute of an input event object is the user-entered value of the input.

Two-Way Databinding
  1. He just explains what two-way binding is. It’s the same as v-model in Vue.

Understanding Directives
  1. Directives are instructions in the DOM.

  2. Component tags in our templates are an example of such instructions.

  3. There are directives with a template (like components) and directives without templates.

  4. Typically you’ll create directives that are placed in your templates like HTML attributes.

  5. He gives an example of an appTurnGreen directive.

  6. Example code:

    @Directive({
        selector: '[appTurnGreen]'
    })
    export class TurnGreenDirective {
        ...
    }
Using ngIf to Output Data Conditionally
  1. So far we haven’t used any directives aside from components (which are considered directives).

  2. The syntax is *ngIf ="expression"

    1. The * identifies this directive as a “structural” directive, meaning it can change the structure of the DOM.

Enhancing ngIf with an Else Condition
  1. The syntax is actually pretty different from Vue:

    <p *ngIf="serverCreated" else noServer>Lorem ipsum</p>
    <ng-template noServer>
      <p>Lorem ipsum</p>
    </ng-template>
    1. The # identifies a local reference.

Styling Elements Dynamically with ngStyle
  1. The other type of directives are “attribute directives”, which don’t have a leading “*”.

  2. To use the ngStyle directive we need to surround it in square brackets.

    1. His example: <p [ngStyle]="{backgroundColor: getColor()}">

  3. NW note: The equivalent in Vue is :style=

  4. He spends a minute making sure that we understand that the square brackets (property binding) and the directive name are two different features of Angular.

Applying CSS Classes Dynamically with ngClass
  1. ngClass allows you to dynamically set CSS classes.

  2. This works like in Vue.

  3. It takes an object where the keys are the CSS classes and the values are expressions to determine whether to enable that CSS class.

Outputting Lists with ngFor
  1. The syntax is *ngFor="let obj of objs"

Getting the Index when using ngFor
  1. The syntax is *ngIf="let obj of objs; let i = index"

Section 4: Debugging

Understanding Angular Error Messages
  1. Open the Chrome devtools and check the console.

  2. He examines the following example error that shows up in the console:

    EXCEPTION: vendor.bundle.js:33928
    Error in ./AppComponent class
    AppComponent - inline template:4:6
    caused by: Cannot read property 'push'
    of undefined
  3. The first important part is that it is telling us the error is in the ./AppComponent component.

  4. The second important clue is that it’s in the “inline template”, with line number 4 and column number 6.

    1. Unfortunately the “line 4, column 6” part is not helpful to us, because that’s the line in the compiled version of the code rather than the source code.

  5. The last piece of important information is the message “Cannot read property ‘push’ of undefined”.

    1. This is how we’ll actually find the error: there’s only one place where we call “push” in our AppComponent code.

  6. Another way to find the error would be to notice it is raised when we click the button, and therefore is likely to be somewhere in the function that handles that button click.

  7. The issue in this particular case is that we’re defining the servers variable but not setting its initial value to an empty array.

  8. So the takeaway is: try to use the error message in the console to identify which file/component is the source of the error, and the particular error it’s encountering in that file/component, and that should hopefully give you enough information to track down what’s happening.

Debugging Code in the Browser Using Sourcemaps
  1. Sometimes you’ll have problems that don’t produce an error message, like the last item in a list not being deleted when you click on it.

  2. In the Chrome Devtools, go to the Sources tab.

  3. The main.bundle.js is the actual file being used by the browser, but it’s not our original source. If we try to set a breakpoint in the main.bundle.js file Chrome will jump us to the relevant source file.

  4. These file support “source maps” allow Chrome to map the bundled JavaScript code that’s actually getting executed to the original source code.

  5. While the code is halted by a breakpoint, you can hover over variables in the code to see their values.

  6. To directly browser your source files, go to the webpack:// section in the left sidebar of the “Sources” tab, then expand the ./src/app/ directory.

Section 5: Components & Databinding Deep Dive

Module Introduction
  1. We’re going to dive deeper into components and databinding.

  2. We’re going to improve an example project using components and databinding.

Splitting Apps into Components
  1. Our example app has two text fields that allow us to define a “Server Name” and a “Server Content”, and two buttons that allow us to “Add Server” or “Add Server Blueprint”, with the only difference between a server and a server blueprint being how the server content text field is displayed (with all servers and blueprints also being shown on this single page).

  2. Right now all the code is in our AppComponent class.

  3. We could create a new component for where we create new servers, and a component for displaying a created server/blueprint.

  4. He uses the CLI to create the two new components: ng g c component-name --spec false

    1. --spec false makes it so that no testing files will be created for this component.

  5. He cuts the relevant code from the AppComponent template file and component file and pastes it into the new components.

  6. He wants to keep the servers variable in the AppComponent because we need to access it from the two child components (the “input” component and the “display” component).

  7. Breaking up the code this way has broken our app because we don’t have a way to pass data between our components. We’re going to fix that next.

Property & Event Binding Overview
Binding to Custom Properties
Assigning an Alias to Custom Properties
Binding to Custom Events
Assigning an Alias to Custom Events
Custom Property and Event Binding Summary
Understanding View Encapsulation
More on View Encapsulation
Using Local References in Templates
@ViewChild() in Angular 8+
Getting Access to the Template & DOM with @ViewChild
Projecting Content into Components with ng-content
Understanding the Component Lifecycle
Seeing Lifecycle Hooks in Action
Lifecycle Hooks and Template Access
@ContentChild() in Angular 8+
Getting Access to ng-content with @ContentChild
Wrap Up

Section 7: Directives Deep Dive

Section 9: Using Services & Dependency Injection

Section 11: Changing Pages with Routing

Section 13: Understanding Observables

Section 15: Handling Forms

Section 17: Using Pipes to Transform Output

Section 18: Making Http Requests

Section 20: Authentication & Route Protection in Angular

Section 21: Dynamic Components

Section 22: Angular Modules & Optimizing Angular Apps

Section 23: Deploying an Angular App

Section 24: Standalone Components

Section 25: Angular Signals

Section 26: Using NgRx for State Management