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.

angular
Filter by
Sorted by
Tagged with
2122 votes
51 answers
1.7m views

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
1875 votes
35 answers
829k views

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.8k
1489 votes
27 answers
836k views

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
  • 17.1k
1336 votes
52 answers
1.4m views

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
1196 votes
24 answers
2.1m views

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
  • 35k
1087 votes
25 answers
747k views

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.4k
1045 votes
31 answers
415k views

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.4k
1028 votes
14 answers
669k views

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.4k
1003 votes
24 answers
1.4m views

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
935 votes
37 answers
1.3m views

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
922 votes
11 answers
1.7m views

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.5k
892 votes
49 answers
1.7m views

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 ...
ForestG's user avatar
  • 17.7k
861 votes
21 answers
660k views

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
  • 12.4k
758 votes
44 answers
1.1m views

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
  • 44.4k
746 votes
36 answers
1.5m views

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,859
745 votes
23 answers
852k views

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
741 votes
15 answers
974k views

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
  • 8,033
737 votes
28 answers
949k views

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
686 votes
21 answers
754k views

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
  • 85.5k
677 votes
31 answers
739k views

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
  • 16.4k
647 votes
19 answers
485k views

*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
  • 12.2k
647 votes
4 answers
113k views

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.8k
647 votes
14 answers
66k views

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.7k
614 votes
6 answers
515k views

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 Bimar's user avatar
  • 7,431
585 votes
27 answers
603k views

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
  • 47.7k
571 votes
24 answers
614k views

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,249
570 votes
31 answers
522k views

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
558 votes
11 answers
369k views

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
558 votes
12 answers
167k views

@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
551 votes
28 answers
752k views

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,496
545 votes
16 answers
709k views

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.8k
529 votes
6 answers
205k views

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
513 votes
14 answers
865k views

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
  • 47.7k
513 votes
6 answers
1.1m views

(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
509 votes
49 answers
472k views

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,148
505 votes
43 answers
743k views

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
495 votes
4 answers
405k views

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,389
486 votes
12 answers
216k views

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
482 votes
29 answers
280k views

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.2k
459 votes
9 answers
377k views

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
456 votes
10 answers
317k views

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
  • 10.1k
446 votes
23 answers
498k views

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
435 votes
19 answers
482k views

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.9k
429 votes
13 answers
762k views

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
  • 35k
424 votes
3 answers
558k views

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
422 votes
9 answers
368k views

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
420 votes
21 answers
877k views

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
  • 15k
414 votes
16 answers
683k views

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
412 votes
26 answers
635k views

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,187
412 votes
21 answers
416k views

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.7k

1
2 3 4 5
6082