Angular 2 Hover event

If you want to perform a hover like event on any HTML element, then you can do it like this. HTML <div (mouseenter) =”mouseEnter(‘div a’) ” (mouseleave) =”mouseLeave(‘div A’)”> <h2>Div A</h2> </div> <div (mouseenter) =”mouseEnter(‘div b’)” (mouseleave) =”mouseLeave(‘div B’)”> <h2>Div B</h2> </div> Component import { Component } from ‘@angular/core’; @Component({ moduleId: module.id, selector: ‘basic-detail’, templateUrl: … Read more

When to use Interface and Model in TypeScript / Angular

Interfaces are only at compile time. This allows only you to check that the expected data received follows a particular structure. For this you can cast your content to this interface: this.http.get(‘…’) .map(res => <Product[]>res.json()); See these questions: How do I cast a JSON object to a typescript class How to get Date object from … Read more

Angular2 material dialog has issues – Did you add it to @NgModule.entryComponents?

Angular 9.0.0 < Since 9.0.0 with Ivy, the entryComponents property is no longer necessary. See deprecations guide. Angular 9.0.0 > You need to add dynamically created components to entryComponents inside your @NgModule @NgModule({ declarations: [ AppComponent, LoginComponent, DashboardComponent, HomeComponent, DialogResultExampleDialog ], entryComponents: [DialogResultExampleDialog] Note: In some cases entryComponents under lazy loaded modules will not work, … Read more

How to reload the current route with the angular 2 router

Create a function in the controller that redirects to the expected route like so redirectTo(uri:string){ this.router.navigateByUrl(“https://stackoverflow.com/”, {skipLocationChange: true}).then(()=> this.router.navigate([uri])); } then use it like this this.redirectTo(‘//place your uri here’); this function will redirect to a dummy route and quickly return to the destination route without the user realizing it.

@HostBinding and @HostListener: what do they do and what are they for?

A quick tip that helps me remember what they do – HostBinding(‘value’) myValue; is exactly the same as [value]=”myValue” And HostListener(‘click’) myClick(){ } is exactly the same as (click)=”myClick()” HostBinding and HostListener are written in directives and the other ones (…) and [..] are written inside templates (of components).

Get current url in Angular [duplicate]

With pure JavaScript: console.log(window.location.href) Using Angular: this.router.url import { Component } from ‘@angular/core’; import { Router } from ‘@angular/router’; @Component({ template: ‘The href is: {{href}}’ /* Other component settings */ }) export class Component { public href: string = “”; constructor(private router: Router) {} ngOnInit() { this.href = this.router.url; console.log(this.router.url); } } The plunkr is … Read more

Angular 2 optional route parameter

You can define multiple routes with and without parameter: @RouteConfig([ { path: ‘/user/:id’, component: User, name: ‘User’ }, { path: ‘/user’, component: User, name: ‘Usernew’ } ]) and handle the optional parameter in your component: constructor(params: RouteParams) { var paramId = params.get(“id”); if (paramId) { … } } See also the related github issue: https://github.com/angular/angular/issues/3525

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