Do I need to complete a Subject for it to be garbage collected?

If you look at the source for Subject.complete, you’ll find the answer: complete() { if (this.closed) { throw new ObjectUnsubscribedError(); } this.isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].complete(); } this.observers.length = 0; } Calling … Read more

MAT_DATE_FORMATS definition/meaning of fields

Well, I figured out the following: parse: { dateInput: ‘DD.MM.YYYY’, }, display: { dateInput: ‘DD.MM.YYYY’, monthYearLabel: ‘MMM YYYY’, dateA11yLabel: ‘LL’, monthYearA11yLabel: ‘MMMM-YYYY’, }, with parse.dateInput: you can let the user enter any type of date with any format, and the date adapter will reformat it to the format you specify in this attribute with display.dateInput … Read more

NgRx – Order of execution of Reducers and Effects

Edit: NgRx effects fire after all reducers for that action have executed. That order is guaranteed. The reduced state is the payload of your effects. Found the following comment in lifecycle_hooks.d.ts in the NgRx effects-build project: By default, effects are merged and subscribed to the store. Implement the OnRunEffects interface to control the lifecycle of … Read more

How to subscribe to event emitter once?

A call to subscribe returns an instance of Disposable, which has a method dispose. Or if you are using RxJS 5, dispose has been renamed to unsubscribe (thanks @EricMartinez). And from the RxJS docs: …when we’re no longer interested in receiving the data as it comes streaming in, we call dispose on our subscription. Store … Read more

Angular 14 strictly typed reactive forms – How to type FormGroup model using existing interface

I also ran into this because I always assign my FormGroup later and I was not happy about having to add a ton of boilerplate types on every FormGroup declaration. It felt like I was repeating myself, so what I ended up doing was creating a utility type which has been working well. export type … Read more

Manually trigger pipe update

First way: paremeter One way to make a Pure Pipe becoming impure is add a parameter to your Pipe. when you want to refresh, just change the parameter. Second way: without parameter Pure Pipe will be fired when its input has a new instance. So with TypeScript 2.1+, the below code will copy the original … Read more

Angular2 View Not Changing After Data Is Updated

So I finally found a solution that I like. Following the answer in this post How to update view after change in angular2 after google event listener fired I updated myList within zone.run() and now my data is updated in my view like expected. MyService.ts /// <reference path=”../../../typings/tsd.d.ts” /> // Import import {NgZone} from ‘angular2/angular2’; … Read more

Static Methods and Angular 2 Services in JavaScript ES6

Static methods of a class, unlike instance methods, belong to (are visible on) the class itself (not an instance of it). They do not depend on the instance members of a class and will usually take input from the parameters, perform actions on it, and return some result. They act independently. They do make sense … Read more