Call child component method from parent class – Angular

You can do this by using @ViewChild for more info check this link With type selector child component @Component({ selector: ‘child-cmp’, template: ‘<p>child</p>’ }) class ChildCmp { doSomething() {} } parent component @Component({ selector: ‘some-cmp’, template: ‘<child-cmp></child-cmp>’, directives: [ChildCmp] }) class SomeCmp { @ViewChild(ChildCmp) child:ChildCmp; ngAfterViewInit() { // child is set this.child.doSomething(); } } With … Read more

Angular2 @Input to a property with get/set

You could set the @Input on the setter directly, as described below: _allowDay: boolean; get allowDay(): boolean { return this._allowDay; } @Input() set allowDay(value: boolean) { this._allowDay = value; this.updatePeriodTypes(); } See this Plunkr: https://plnkr.co/edit/6miSutgTe9sfEMCb8N4p?p=preview.

How do I download a file with Angular2 or greater

The problem is that the observable runs in another context, so when you try to create the URL var, you have an empty object and not the blob you want. One of the many ways that exist to solve this is as follows: this._reportService.getReport().subscribe(data => this.downloadFile(data)),//console.log(data), error => console.log(‘Error downloading the file.’), () => console.info(‘OK’); … Read more

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

What’s the difference between markForCheck() and detectChanges()

detectChanges() : void Checks the change detector and its children. It means, if there is a case where any thing inside your model (your class) has changed but it hasn’t reflected the view, you might need to notify Angular to detect those changes (detect local changes) and update the view. Possible scenarios might be : … Read more

Angular 2 Checkbox Two Way Data Binding

You can remove .selected from saveUsername in your checkbox input since saveUsername is a boolean. Instead of [(ngModel)] use [checked]=”saveUsername” (change)=”saveUsername = !saveUsername” Edit: Correct Solution: <input type=”checkbox” [checked]=”saveUsername” (change)=”saveUsername = !saveUsername”/> Update: Like @newman noticed when ngModel is used in a form it won’t work. However, you should use [ngModelOptions] attribute like (tested in Angular 7): … Read more

Can’t bind to ‘routerLink’ since it isn’t a known property

You need to add RouterModule to imports of every @NgModule() where components use any component or directive from (in this case routerLink and <router-outlet>. import {RouterModule} from ‘@angular/router’; @NgModule({ declarations:[YourComponents], imports:[RouterModule] declarations: [] is to make components, directives, pipes, known inside the current module. exports: [] is to make components, directives, pipes, available to importing … Read more

What’s the difference between an Angular component and module

Components control views (html). They also communicate with other components and services to bring functionality to your app. Modules consist of one or more components. They do not control any html. Your modules declare which components can be used by components belonging to other modules, which classes will be injected by the dependency injector and … Read more

How to use moment.js library in angular 2 typescript app?

Update April 2017: As of version 2.13.0, Moment includes a typescript definition file. https://momentjs.com/docs/#/use-it/typescript/ Just install it with npm, in your console type npm install –save moment And then in your Angular app, import is as easy as this: import * as moment from ‘moment’; That’s it, you get full Typescript support! Bonus edit: To … Read more

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