How can I add Font Awesome to my Aurelia project using npm?

Don’t add font-awesome resources to aurelia.json – you’d need font files too, which Aurelia don’t process. Instead, take the following steps. First, if you added anything for font-awesome already to your aurelia.json file, remove it again. Add new file prepare-font-awesome.js in folder \aurelia_project\tasks and insert the below code. It copies font-awesome resource files to output … Read more

Property change subscription with Aurelia

In some plugins I’ve been using DI to get the ObserverLocator instance from the container: import {inject} from ‘aurelia-dependency-injection’; // or from ‘aurelia-framework’ import {ObserverLocator} from ‘aurelia-binding’; // or from ‘aurelia-framework’ @inject(ObserverLocator) export class Foo { constructor(observerLocator) { this.observerLocator = observerLocator; } … } You can then do something like this: var subscription = this.observerLocator … Read more

How to assign string | undefined to string in TypeScript?

The typescript compiler performs strict null checks, which means you can’t pass a string | undefined variable into a method that expects a string. To fix this you have to perform an explicit check for undefined before calling luminaireReplaceLuminaire(). In your example: private selectedSerialForReplace(): string | undefined { return this.selectedSerials.pop(); } luminaireReplaceLuminaire(params: { “serial”: string; … Read more

How to resolve “TypeError: NetworkError when attempting to fetch resource.”

This is probably related to Cross-Origin Resource Sharing (CORS). The Cross-Origin Resource Sharing (CORS) mechanism gives web servers cross-domain access controls, which enable secure cross-domain data transfers. Modern browsers use CORS in an API container – such as XMLHttpRequest or Fetch – to mitigate risks of cross-origin HTTP requests. (Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS If you have Chrome … Read more

Handle a 500 response with the fetch api

Working Solution Combining then with catch works. fetch(‘http://some-site.com/api/some.json’) .then(function(response) { // first then() if(response.ok) { return response.text(); } throw new Error(‘Something went wrong.’); }) .then(function(text) { // second then() console.log(‘Request successful’, text); }) .catch(function(error) { // catch console.log(‘Request failed’, error); }); Details fetch() returns a Promise containing a Response object. The Promise can become either … Read more

How to set up minimal Aurelia project from scratch

Install the jspm command line interface. jspm is a package manager for client-side dependencies. Read up on it… it’s great. npm install jspm -g Create a folder for the project. mkdir minimal cd minimal Initialize jspm client package management… Accept all the defaults EXCEPT use the Babel transpiler option (vs Traceur) jspm init Enable all … Read more

Aurelia delegate vs trigger: how do you know when to use delegate or trigger?

Use delegate except when you cannot use delegate. Event delegation is a technique used to improve application performance. It drastically reduces the number of event subscriptions by leveraging the “bubbling” characteristic of most DOM events. With event delegation, handlers are not attached to individual elements. Instead, a single event handler is attached to a top-level … Read more

tech