Avoid returning index.html for API calls

While writing an asp.net hosted Blazor WASM app, I’ve noticed that when I call an API on my server I receive the contents of index.html when I am expecting a 404 error. TL;DR Explanation When you first request a URL from the host and nothing is found at that address, the server will serve the …
Continue reading Avoid returning index.html for API calls

Assigning a piped async result to a variable in an Angular view

If you have an Observable<x> in your component you might find yourself doing something like this {{ ( source$ | async)?.property1 }}{{ ( source$ | async)?.property2 }} This will subscribe to the source$ observable more than once. A commonly used technique to avoid this is to assign the result of the async into a view …
Continue reading Assigning a piped async result to a variable in an Angular view

Implementing a really simple Elvis Operator in TypeScript

Here is a simple routine that implements what is known as the Elvis Operator in TypeScript. In C# you can write code like thisNullable<int> age = person?.BestFriend?.Mother?.CurrentHusband?.Age); If any of the values along the way it will return a null rather than throwing a NullReferenceException. Using the class in my previous blog Get a Lambda expression …
Continue reading Implementing a really simple Elvis Operator in TypeScript

A type safe way of creating Angular ReactiveForms and FormGroups

If, like myself, you prefer as many of your coding mistakes to be identified at compile time as possible then you might like the following example. The FormBuilder in Angular expects us to identify our FormControls with a string name. If ever the API of your server changes then of course the names of those …
Continue reading A type safe way of creating Angular ReactiveForms and FormGroups

Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ng:///DynamicTestModule – Solved (Angular testing)

If when you run your tests you see an error similar to this Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘ng:///DynamicTestModule/xxxxxxComponent_Host.ngfactory.js It means something in your component is throwing an exception and the test framework is returning a wrapped exception. To see the actual exception run ng test with -sm=false as a parameter …
Continue reading Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ng:///DynamicTestModule – Solved (Angular testing)

Angular – How to create a data aware custom component

Introduction This blog will demonstrate how to create an Angular component that you are able to add [ngModel] [formControl] and [formControlName] attributes to your custom component, and have your component correct implement the features required to work with Angular forms. Setting up the ngModule First add FormsModule and ReactiveFormsModule to your main NgModule’s import declaration …
Continue reading Angular – How to create a data aware custom component

TypeScript – A polyfill to extend the Object class to add a values property to complement the keys property

I expect you’ve used Object.keys at some point. Here is how to extend the Object class to add a values property. This kind of thing is useful when you have a lookup of keys where all of the values are the same type, such as the following object you’d expect to see in a Redux …
Continue reading TypeScript – A polyfill to extend the Object class to add a values property to complement the keys property

TypeScript – Get a Lambda expression as a string

One of the things I really like about C# is the ability to convert a lambda into a string. It’s useful for doing all kinds of things, especially when you are calling a 3rd party library’s method that expects a string identifying a member of an object. I saw this was lacking in TypeScript, which …
Continue reading TypeScript – Get a Lambda expression as a string