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

WARNING in budgets, maximum exceeded for initial

Open angular.json file and find budgets keyword. It should look like: “budgets”: [ { “type”: “initial”, “maximumWarning”: “2mb”, “maximumError”: “5mb” } ] As you’ve probably guessed you can increase the maximumWarning value to prevent this warning, i.e.: “budgets”: [ { “type”: “initial”, “maximumWarning”: “4mb”, <=== “maximumError”: “5mb” } ] What does budgets mean? A performance … Read more

Triggering change detection manually in Angular

Try one of these: ApplicationRef.tick() – similar to AngularJS’s $rootScope.$digest() — i.e., check the full component tree NgZone.run(callback) – similar to $rootScope.$apply(callback) — i.e., evaluate the callback function inside the Angular zone. I think, but I’m not sure, that this ends up checking the full component tree after executing the callback function. ChangeDetectorRef.detectChanges() – similar … Read more

How can I get new selection in “select” in Angular 2?

If you don’t need two-way data-binding: <select (change)=”onChange($event.target.value)”> <option *ngFor=”let i of devices”>{{i}}</option> </select> onChange(deviceValue) { console.log(deviceValue); } For two-way data-binding, separate the event and property bindings: <select [ngModel]=”selectedDevice” (ngModelChange)=”onChange($event)” name=”sel2″> <option [value]=”i” *ngFor=”let i of devices”>{{i}}</option> </select> export class AppComponent { devices=”one two three”.split(‘ ‘); selectedDevice=”two”; onChange(newValue) { console.log(newValue); this.selectedDevice = newValue; // … … Read more

What is the difference between declarations, providers, and import in NgModule?

Angular Concepts imports makes the exported declarations of other modules available in the current module declarations are to make directives (including components and pipes) from the current module available to other directives in the current module. Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported. providers … Read more

Error when trying to inject a service into an angular component “EXCEPTION: Can’t resolve all parameters for component”, why?

Import it from the file where it is declared directly instead of the barrel. I don’t know what exactly causes the issue but I saw it mentioned several times (probably some kind of circular dependency). It should also be fixable by changing the order of the exports in the barrel (don’t know details, but was … Read more

Can’t bind to ‘formControl’ since it isn’t a known property of ‘input’ – Angular2 Material Autocomplete issue

While using formControl, you have to import ReactiveFormsModule to your imports array. Example: import {FormsModule, ReactiveFormsModule} from ‘@angular/forms’; @NgModule({ imports: [ BrowserModule, FormsModule, ReactiveFormsModule, MaterialModule, ], … }) export class AppModule {}

Unable to resolve dependency tree error when installing npm packages

This is not related to an HTTP proxy. You have dependency conflict (incorrect and potentially broken dependency) as it says, so try to run the command with –force, or –legacy-peer-deps. If it doesn’t take effect, the temporary solution is using prior versions of the Node.js (downgrading the Node.js version) as it causes this kind of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)