How to display the app version in Angular?

If you want to use/show the version number in your angular app please do the following: Prerequisites: Angular file and folder structure created via Angular CLI Steps for Angular 6.1 (TS 2.9+) till Angular 11 In your /tsconfig.json (sometimes also necessary in /src/tsconfig.app.json) enable the following option (webpack dev server restart required afterwards): “compilerOptions”: { … Read more

Can’t bind to ‘ngForOf’ since it isn’t a known property of ‘tr’ (final release)

Add BrowserModule to imports: [] in @NgModule() if it’s the root module (AppModule), otherwise the CommonModule. // older Angular versions // import {BrowserModule, CommonModule} from ‘@angular/common’; import { BrowserModule } from ‘@angular/platform-browser’ .. .. @NgModule({ imports: [BrowserModule, /* or CommonModule */], .. })

Adding a HTTP header to the Angular HttpClient doesn’t send the header, why?

The instances of the new HttpHeader class are immutable objects. Invoking class methods will return a new instance as result. So basically, you need to do the following: let headers = new HttpHeaders(); headers = headers.set(‘Content-Type’, ‘application/json; charset=utf-8’); or const headers = new HttpHeaders({‘Content-Type’:’application/json; charset=utf-8′}); Update: adding multiple headers let headers = new HttpHeaders(); headers … Read more

What is the purpose of providedIn with the Injectable decorator when generating Services in Angular 6?

providedIn: ‘root’ is the easiest and most efficient way to provide services since Angular 6: The service will be available application wide as a singleton with no need to add it to a module’s providers array (like Angular <= 5). If the service is only used within a lazy loaded module it will be lazy … Read more

How to execute only one test spec with angular-cli

Each of your .spec.ts file have all its tests grouped in describe block like this: describe(‘SomeComponent’, () => {…} You can easily run just this single block, by prefixing the describe function name with f: fdescribe(‘SomeComponent’, () => {…} If you have such function, no other describe blocks will run. Btw. you can do similar … Read more

Global Events in Angular

There is no equivalent to $scope.emit() or $scope.broadcast() from AngularJS. EventEmitter inside of a component comes close, but as you mentioned, it will only emit an event to the immediate parent component. In Angular, there are other alternatives which I’ll try to explain below. @Input() bindings allows the application model to be connected in a … Read more

Dynamic tabs with user-click chosen components

update Angular 5 StackBlitz example update ngComponentOutlet was added to 4.0.0-beta.3 update There is a NgComponentOutlet work in progress that does something similar https://github.com/angular/angular/pull/11235 RC.7 Plunker example RC.7 // Helper component to add dynamic components @Component({ selector: ‘dcl-wrapper’, template: `<div #target></div>` }) export class DclWrapper { @ViewChild(‘target’, {read: ViewContainerRef}) target: ViewContainerRef; @Input() type: Type<Component>; cmpRef: … Read more