How to add “class” to host element?

This way you don’t need to add the CSS outside of the component: @Component({ selector: ‘body’, template: ‘app-element’, // prefer decorators (see below) // host: {‘[class.someClass]’:’someField’} }) export class App implements OnInit { constructor(private cdRef:ChangeDetectorRef) {} someField: boolean = false; // alternatively also the host parameter in the @Component()` decorator can be used @HostBinding(‘class.someClass’) someField: … Read more

How can I write data attributes using Angular?

Use attribute binding syntax instead <ol class=”viewer-nav”><li *ngFor=”let section of sections” [attr.data-sectionvalue]=”section.value”>{{ section.text }}</li> </ol> or <ol class=”viewer-nav”><li *ngFor=”let section of sections” attr.data-sectionvalue=”{{section.value}}”>{{ section.text }}</li> </ol> See also : How to add conditional attribute in Angular 2?

Angular 2 Scroll to top on Route Change

Angular 6.1 and later: Angular 6.1 (released on 2018-07-25) added built-in support to handle this issue, through a feature called “Router Scroll Position Restoration”. As described in the official Angular blog, you just need to enable this in the router configuration like this: RouterModule.forRoot(routes, {scrollPositionRestoration: ‘enabled’}) Furthermore, the blog states “It is expected that this … Read more

tech