On New Year’s Eve 2017, Maxim Salnikov proclaimed 2018 to be the year of Progressive Web Apps. The #YearOfPWA is almost over now and we’ve come a long way. Here’s a short recap of all the fantastic things that happened.
Continue reading Year of PWA: A SummaryCategory: Angular
Angular & TypeScript: How to Import RxJS Correctly?
Important update: RxJS 5.5 brought us Pipeable Operators that eliminate some of the problems noted below. If you can update to TypeScript 2.4, RxJS 5.5, Angular 5 and Angular CLI 1.5, you should definitely go with Pipeable Operators.
Angular has some third-party dependencies, one of which is RxJS, a library which makes reactive programming very easy to use. The library is obtained as an npm package. In order to use functionality from the RxJS library, it has to be imported first. So before you can use an operator such as map in the following snippet, it has to be imported:
route.params .map(params => params.id) .subscribe(id => console.log(id));
Whereas IDEs such as WebStorm (prior to 2017.2) or Visual Studio Code do a good job for auto-importing symbols, they don’t suggest anything at all for RxJS symbols. Both IDEs simply print the following error message from TypeScript:
Property ‘map’ does not exist on type ‘Observable’.
Continue reading Angular & TypeScript: How to Import RxJS Correctly?
Angular & TypeScript: Writing Safer Code with strictNullChecks
On May 4, Angular 4.1.1 was released. This release fulfils a promise already made for Angular 4.1: Adding support for TypeScript’s strictNullChecks compiler option added in TypeScript 2.0.
Strict Null Checking = Safer Code
This transpiler flag enables us to write safer code. TypeScript with strict null checking enabled feels even more comfortable for developers with a static-typed language background. Without strict null checking, assigning null or undefined for instance to a variable of type number is perfectly possible:
Continue reading Angular & TypeScript: Writing Safer Code with strictNullChecks
Angular 2 & Protractor Timeout: Here’s How to Fix It
Testability is an important discipline in application development. Angular was always built with testability in mind. Protractor is Angular’s end-to-end testing framework. It was originally created for AngularJS, the first edition of the popular SPA framework, but works perfectly with Angular 2 by simply setting useAllAngular2AppRoots to true in Protractor’s config.js. In addition, you can optionally specify an element name for the rootElement property to exclusively test against this element.
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
useAllAngular2AppRoots: true,
// rootElement: 'root-element'
};
However, if you are using Angular 2 and Protractor in combination, you might stumble upon one of the following error messages:
Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Here’s how to fix those errors:
Continue reading Angular 2 & Protractor Timeout: Here’s How to Fix It