How can I select an element in a component template?

Does anybody know how to get hold of an element defined in a component template? Polymer makes it really easy with the $ and $$. I was just wondering how to go about it in Angular. Take the example from the tutorial: import {Component} from ‘@angular/core’; @Component({ selector:’display’, template:` <input #myname (input)=”updateName(myname.value)”/> <p>My name : … Read more

What is the equivalent of ngShow and ngHide in Angular 2+?

I have a number of elements that I want to be visible under certain conditions. In AngularJS I would write <div ng-show=”myVar”>stuff</div> How can I do this in Angular 2+? 2Best Answer 21 The hidden property can be used for that [hidden]=”!myVar” See also https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden issues hidden has some issues though because it can conflict … Read more

How to detect when an @Input() value changes in Angular?

I have a parent component (CategoryComponent), a child component (videoListComponent) and an ApiService. I have most of this working fine i.e. each component can access the json api and get its relevant data via observables. Currently video list component just gets all videos, I would like to filter this to just videos in a particular … Read more

Could not find module “@angular-devkit/build-angular”

After updating to Angular 6.0.1, I get the following error on ng serve: Could not find module “@angular-devkit/build-angular” from “/home/Projects/myProjectName”. Error: Could not find module “@angular-devkit/build-angular” from “/home/Projects/myProjectName”. at Object.resolve (/home/Projects/myProjectName/node_modules/@angular-devkit/core/node/resolve.js:141:11) at Observable.rxjs_1.Observable [as _subscribe] (/home/Projects/myProjectName/node_modules/@angular-devkit/architect/src/architect.js:132:40) ng update says everything is in order. Deleting node_modules folder and a fresh npm install install did not help … Read more

How can I use “*ngIf else”?

I’m using Angular and I want to use *ngIf else (available since version 4) in this example: <div *ngIf=”isValid”> content here … </div> <div *ngIf=”!isValid”> other content here… </div> How can I achieve the same behavior with ngIf else? 19 s 19 Angular 4 and 5: Using else: <div *ngIf=”isValid;else other_content”> content here … </div> … Read more

Angular/RxJS When should I unsubscribe from `Subscription`

When should I store the Subscription instances and invoke unsubscribe() during the ngOnDestroy life cycle and when can I simply ignore them? Saving all subscriptions introduces a lot of mess into component code. HTTP Client Guide ignore subscriptions like this: getHeroes() { this.heroService.getHeroes() .subscribe( heroes => this.heroes = heroes, error => this.errorMessage = <any>error); } … Read more