What is the meaning of question mark in expressions in Angular 2?

Edit Since the original answer, Ecmascript, and Typescript (in 3.7) have both added the ?. (called the optional chaining operator) operator. See the PR for details. Original answer This is not a Typescript operator. Angular 2 has a safe navigation operator in templates. values?.listArray is equivalent to values != null ? values.listArray: null More info … Read more

const enum in Typescript

Just remove the const modifier. const in an enum means the enum is fully erased during compilation. Const enum members are inlined at use sites. You can can’t index it by an arbitrary value. In other words, the following TypeScript code const enum Snack { Apple = 0, Banana = 1, Orange = 2, Other … Read more

Rxjs Retry with Delay function

delay() is used to introduce a delay between events emitted by the observable. But the observable never emits any event. It just errors immediately. What you’re looking for is retryWhen(), which allows deciding after how long to retry: RxJS 5: .retryWhen(errors => errors.delay(1000).take(10)) RxJS 6: import { retryWhen, delay, take } from ‘rxjs/operators’ someFunction().pipe( // … Read more

Pass config data using forRoot

You are almost there, simply provide both SampleService and config in your module like below: export class SampleModule { static forRoot(config: CustomConfig): ModuleWithProviders<SampleModule> { // User config get logged here console.log(config); return { ngModule: SampleModule, providers: [SampleService, {provide: ‘config’, useValue: config}] }; } } @Injectable() export class SampleService { foo: string; constructor(@Inject(‘config’) private config:CustomConfig) { … Read more

‘R’ could be instantiated with an arbitrary type which could be unrelated to ‘Response’

Generic functions in TypeScript act as a function representing every possible specification of its generic type parameters, since it’s the caller of the function that specifies the type parameter, not the implementer: type GenericFunction = <T>(x: T) => T; const cantDoThis: GenericFunction = (x: string) => x.toUpperCase(); // error! // doesn’t work for every T … Read more

ERROR in TypeError: Cannot read property ‘flags’ of undefined

edit If you use angular 9.1.6 it should be fine now npm update @angular/cli @angular/core original post Something is broken in Angular 9.1.5 – if you run the following it should work: npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4 ng build Just spent about 4-5 hours trying to fix it … Read more

How to place a dynamic component in a container

You can get the ViewContainerRef of the current component by or from an element in the view of the current component @Component({ selector: ‘…’, directives: [OtherComponent, FooComponent], template: ` <other-component></other-component> <foo-component #foo></foo-component> <div #div></div>` }) export class SomeComponent { // `ViewContainerRef` from an element in the view @ViewChild(OtherComponent, {read: ViewContainerRef}) other; @ViewChild(‘foo’, {read: ViewContainerRef}) foo; … Read more