Questions tagged [angular]

Questions about Angular (not to be confused with AngularJS), the web framework from Google. Use this tag for Angular questions which are not specific to an individual version. For the older AngularJS (1.x) web framework, use the AngularJS tag.

Filter by
Sorted by
Tagged with
2072 votes
49 answers

Can't bind to 'ngModel' since it isn't a known property of 'input'

I have this simple input in my component which uses [(ngModel)] : <input type="text" [(ngModel)]="test" placeholder="foo" /> And I get the following error when I ...
Anthony Brenelière's user avatar
1851 votes
34 answers

What is the difference between Promises and Observables?

What is the difference between Promise and Observable in Angular? An example on each would be helpful in understanding both the cases. In what scenario can we use each case?
Rohit's user avatar
  • 18.6k
1471 votes
27 answers

Difference between Constructor and ngOnInit

Angular provides life cycle hook ngOnInit by default. Why should ngOnInit be used, if we already have a constructor?
Haseena P A's user avatar
  • 16.9k
1303 votes
50 answers

Can't bind to 'formGroup' since it isn't a known property of 'form'

The situation I am trying to make what should be a very simple form in my Angular application, but no matter what, it never works. The Angular version Angular 2.0.0 RC5 The error Can't bind to '...
FrancescoMussi's user avatar
1165 votes
24 answers

Angular: conditional class with *ngClass

What is wrong with my Angular code? I am getting the following error: Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass <ol> <li *ngClass="{active: step==='...
daniel's user avatar
  • 34.3k
1083 votes
24 answers

Angular HTML binding

I am writing an Angular application and I have an HTML response I want to display. How do I do that? If I simply use the binding syntax {{myVal}} it encodes all HTML characters (of course). I need ...
Aviad P.'s user avatar
  • 32.1k
1021 votes
29 answers

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 ...
Sergey Tihon's user avatar
  • 12.1k
1011 votes
14 answers

What is the difference between BehaviorSubject and Observable?

I'm looking into the design patterns of RxJS, and I do not understand the difference between BehaviorSubject and Observable. From my understanding, BehaviorSubject can contain a value that may change. ...
Kevin Mark's user avatar
  • 10.2k
977 votes
22 answers

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">...
El houcine bougarfaoui's user avatar
895 votes
10 answers

ngFor with index as value in attribute

I have a simple ngFor loop which also keeps track of the current index. I want to store that index value in an attribute so I can print it. But I can't figure out how this works. I basically have ...
Vivendi's user avatar
  • 20.1k
883 votes
47 answers

Angular 6 - 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 "@...
ForestG's user avatar
  • 17.4k
875 votes
37 answers

Property '...' has no initializer and is not definitely assigned in the constructor

in my Angular app i have a component: import { MakeService } from './../../services/make.service'; import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-vehicle-form', ...
Mikhail Kostiuchenko's user avatar
837 votes
20 answers

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 ...
Jon Catmull's user avatar
  • 11.9k
747 votes
41 answers

How to get current route

The current docs only talk about getting route params, not the actual route segments. For example, if i want to find the parent of current route, how is that possible?
pdeva's user avatar
  • 43.7k
739 votes
23 answers

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+?
Mihai Răducanu's user avatar
727 votes
15 answers

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 ...
Aman Gupta's user avatar
  • 7,893
708 votes
34 answers

Unable to resolve dependency tree error when installing npm packages

When trying to install the npm packages using npm i command, I am getting the following exception: I have tried reinstalling the Node.js package and setting the proxy to off using: set HTTP_PROXY= ...
Pearl's user avatar
  • 8,423
707 votes
25 answers

No provider for HttpClient

After upgrading from angular 4.4 to 5.0 and after updating all HttpModule and Http to HttpClientModule I started to get this error. I also added HttpModule again to be sure it's not due to some ...
Himmet Yelekin's user avatar
667 votes
21 answers

access key and value of object using *ngFor

I am a bit confused about how to get the key and value of an object in angular2 while using *ngFor for iterating over the object. I know in angular 1.x there is a syntax like ng-repeat="(key, value) ...
Pardeep Jain's user avatar
  • 84.2k
657 votes
32 answers

How to detect a route change in Angular?

I am looking to detect a route change in my AppComponent. Thereafter I will check the global user token to see if the user is logged in so that I can redirect the user if the user is not logged in.
AngularM's user avatar
  • 16k
646 votes
14 answers

Huge number of files generated for every Angular project

I wanted to start a simple hello world app for Angular. When I followed the instructions in the official quickstart the installation created 32,000 files in my project. I figured this is some ...
Moshe Shaham's user avatar
  • 15.5k
637 votes
18 answers

*ngIf and *ngFor on same element causing error

I'm having a problem with trying to use Angular's *ngFor and *ngIf on the same element. When trying to loop through the collection in the *ngFor, the collection is seen as null and consequently ...
garethdn's user avatar
  • 12k
632 votes
4 answers

What is the meaning of the "at" (@) prefix on npm packages?

In the Angular Component Router documentation I just stumbled over a npm command I have never seen before and I don't understand what is going on: npm install @angular/router --save What is the ...
jbandi's user avatar
  • 17.6k
576 votes
29 answers

How to go back last page

Is there a smart way to go back last page in Angular 2? Something like this._router.navigate(LASTPAGE); For example, page C has a Go Back button, Page A -> Page C, click it, back to page A. Page B ...
Hongbo Miao's user avatar
  • 45.5k
573 votes
5 answers

WARNING in budgets, maximum exceeded for initial

When building my Angular 7 project with --prod, I receive a warning in budgets. I have an Angular 7 project. I am trying to build it, but I keep getting the following warning: WARNING in budgets, ...
Masoud Bimmar's user avatar
560 votes
24 answers

Error: More than one module matches. Use skip-import option to skip importing the component into the closest module

When I try to create a component in the angular cli, it's showing me this error. How do I get rid of it ? Error: More than one module matches. Use skip-import option to skip importing the component ...
Anamul Haque's user avatar
  • 7,109
560 votes
31 answers

ExpressionChangedAfterItHasBeenCheckedError Explained

Please explain to me why I keep getting this error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Obviously, I only get it in dev mode, it doesn't happen ...
Kevin LeStarge's user avatar
550 votes
28 answers

how to reset <input type = "file"> in Angular

I am developing a metro app with VS2012 and Javascript I want to reset the contents of my file input: <input type="file" id="uploadCaptureInputFile" class="win-content colors" accept="image/*" /&...
Jesus's user avatar
  • 8,466
550 votes
12 answers

@Directive vs @Component in Angular

What is the difference between @Component and @Directive in Angular? Both of them seem to do the same task and have the same attributes. What are the use cases and when to prefer one over another?
Prasanjit Dey's user avatar
546 votes
11 answers

Can't bind to 'formControl' since it isn't a known property of 'input' - Angular2 Material Autocomplete issue

I am trying to use Angular Material Autocomplete component in my Angular 2 project. I added the following to my template. <md-input-container> <input mdInput placeholder="Category" [...
Lahiru Chandima's user avatar
536 votes
16 answers

Binding select element to object in Angular

I'd like to bind a select element to a list of objects -- which is easy enough: @Component({ selector: 'myApp', template: `<h1>My Application</h1> <select [(ngModel)]...
RHarris's user avatar
  • 10.5k
518 votes
6 answers

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

I am trying to understand Angular (sometimes called Angular2+), then I came across @Module: Imports Declarations Providers Following Angular Quick Start
Ramesh Papaganti's user avatar
510 votes
14 answers

How can I get new selection in "select" in Angular 2?

I am using Angular 2 (TypeScript). I want to do something with the new selection, but what I get in onChange() is always the last selection. How can I get the new selection? <select [(ngModel)]="...
Hongbo Miao's user avatar
  • 45.5k
507 votes
49 answers

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

I've built a basic app in Angular, but I have encountered a strange issue where I cannot inject a service into one of my components. It injects fine into any of the three other components I have ...
Keith Otto's user avatar
  • 5,128
502 votes
6 answers

(change) vs (ngModelChange) in angular

Angular 1 does not accept onchange() event, it's only accepts ng-change() event. Angular 2, on the other hand, accepts both (change) and (ngModelChange) events, which both seems to be doing the same ...
Ramesh Rajendran's user avatar
488 votes
4 answers

Triggering change detection manually in Angular

I'm writing an Angular component that has a property Mode(): string. I would like to be able to set this property programmatically not in response to any event. The problem is that in the absence of ...
jz87's user avatar
  • 9,229
483 votes
12 answers

Angular exception: Can't bind to 'ngForIn' since it isn't a known native property

What am I doing wrong? import {bootstrap, Component} from 'angular2/angular2' @Component({ selector: 'conf-talks', template: `<div *ngFor="let talk in talks"> {{talk.title}} by {{talk....
Mark Rajcok's user avatar
480 votes
43 answers

mat-form-field must contain a MatFormFieldControl

We are trying to build our own form-field-Components at our Company. We are trying to wrap material design's Components like this: field: <mat-form-field> <ng-content></ng-content&...
Viktor Eriksson's user avatar
477 votes
28 answers

Angular 2 Scroll to top on Route Change

In my Angular 2 app when I scroll down a page and click the link at the bottom of the page, it does change the route and takes me to the next page but it doesn't scroll to the top of the page. As a ...
Naveed Ahmed's user avatar
  • 10.1k
454 votes
9 answers

Angular - Use pipes in services and components

In AngularJS, I am able to use filters (pipes) inside of services and controllers using syntax similar to this: $filter('date')(myDate, 'yyyy-MM-dd'); Is it possible to use pipes in services/...
POSIX-compliant's user avatar
441 votes
23 answers

Expression ___ has changed after it was checked

Why is the component in this simple plunk @Component({ selector: 'my-app', template: `<div>I'm {{message}} </div>`, }) export class App { message:string = 'loading :('; ...
drew moore's user avatar
  • 31.6k
438 votes
10 answers

What is the difference between Subject and BehaviorSubject?

I'm not clear on the difference between a Subject and a BehaviorSubject. Is it just that a BehaviorSubject has the getValue() function?
Mike Jerred's user avatar
  • 9,591
418 votes
13 answers

Angular 2 change event on every keypress

The change event is only called after the focus of the input has changed. How can I make it so that the event fires on every keypress? <input type="text" [(ngModel)]="mymodel" (change)="...
daniel's user avatar
  • 34.3k
417 votes
3 answers

Can't bind to 'ngIf' since it isn't a known property of 'div' [duplicate]

Can't bind to 'ngIf' since it isn't a known property of 'div'. The element is <div [ngIf]="isAuth" id="sidebar"> And the component is: import SessionService from '../session/...
Ivaylo Ivanov's user avatar
416 votes
20 answers

How do I pass data to Angular routed components?

In one of my Angular 2 routes's templates (FirstComponent) I have a button first.component.html <div class="button" click="routeWithData()">Pass data and route</div> My goal is to ...
dragonmnl's user avatar
  • 14.7k
412 votes
26 answers

How to use jQuery with Angular?

Can anyone tell me, how to use jQuery with Angular? class MyComponent { constructor() { // how to query the DOM element from here? } } I'm aware there are workarounds like ...
Waog's user avatar
  • 7,147
411 votes
19 answers

Property 'value' does not exist on type 'EventTarget'

I am using TypeScript Version 2 for an Angular 2 component code. I am getting error "Property 'value' does not exist on type 'EventTarget'" for below code, what could be the solution. Thanks!...
user584018's user avatar
  • 10.2k
411 votes
16 answers

npm WARN ... requires a peer of ... but none is installed. You must install peer dependencies yourself

I tried to run a project downloaded from github. Unfortunately, during npm install the following warnings were shown. I tried to change the version based on this question. However, I had a problem, ...
user avatar
406 votes
22 answers

How to style child components from parent component's CSS file?

I've got a parent component: <parent></parent> And I want to populate this group with child components: <parent> <child></child> <child></child> <...
Chrillewoodz's user avatar
  • 27.1k
405 votes
9 answers

Convert Promise to Observable

I am trying to wrap my head around observables. I love the way observables solve development and readability issues. As I read, benefits are immense. Observables on HTTP and collections seem to be ...
Krishnan Sriram's user avatar

2 3 4 5