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
305,877
questions
2142
votes
52
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 ...
1883
votes
35
answers
843k
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?
1497
votes
28
answers
851k
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?
1348
votes
52
answers
1.5m
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 '...
1209
votes
24
answers
2.2m
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==='...
1088
votes
25
answers
751k
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 ...
1054
votes
28
answers
432k
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 ...
1032
votes
14
answers
679k
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. ...
1010
votes
25
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">...
963
votes
39
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',
...
928
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 ...
895
votes
49
answers
1.8m
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 ...
875
votes
22
answers
682k
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 ...
770
votes
36
answers
1.6m
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=
...
766
votes
44
answers
1.2m
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?
749
votes
30
answers
993k
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 ...
748
votes
23
answers
860k
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+?
744
votes
15
answers
990k
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 ...
690
votes
21
answers
766k
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) ...
680
votes
31
answers
755k
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.
662
votes
4
answers
118k
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 ...
652
votes
19
answers
493k
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 ...
645
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 ...
627
votes
6
answers
542k
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, ...
589
votes
27
answers
618k
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 ...
573
votes
31
answers
538k
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 ...
571
votes
24
answers
622k
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 ...
563
votes
11
answers
377k
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" [...
557
votes
12
answers
169k
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?
552
votes
28
answers
759k
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/*" /&...
546
votes
16
answers
717k
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)]...
533
votes
6
answers
210k
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
520
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 ...
513
votes
43
answers
771k
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&...
511
votes
14
answers
874k
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)]="...
509
votes
49
answers
476k
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 ...
496
votes
4
answers
414k
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 ...
488
votes
12
answers
220k
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....
482
votes
29
answers
284k
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 ...
468
votes
9
answers
387k
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/...
462
votes
10
answers
327k
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?
451
votes
23
answers
511k
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 :(';
...
439
votes
19
answers
503k
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!...
430
votes
13
answers
773k
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)="...
430
votes
3
answers
573k
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/...
427
votes
9
answers
382k
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 ...
426
votes
22
answers
898k
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 ...
417
votes
21
answers
426k
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>
<...
415
votes
19
answers
206k
views
@ViewChild in *ngIf
Question
What is the most elegant way to get @ViewChild after corresponding element in template was shown?
Below is an example. Also Plunker available.
Component.template.html:
<div id="layout&...
415
votes
26
answers
642k
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 ...