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
1735
votes
48answers
1.1m views

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

I've got the following error when launching my Angular app, even if the component is not displayed. I have to comment out the <input> so that my app works. zone.js:461 Unhandled Promise ...
1656
votes
31answers
626k 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?
1294
votes
27answers
635k 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?
1062
votes
37answers
932k 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 '...
989
votes
24answers
648k 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 ...
888
votes
22answers
1.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==='...
880
votes
11answers
492k views

BehaviorSubject vs Observable?

I'm looking into Angular RxJs patterns and I don't understand the difference between a BehaviorSubject and an Observable. From my understanding, a BehaviorSubject is a value that can change over time ...
866
votes
26answers
262k 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 ...
811
votes
19answers
924k views

How to 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 ...
769
votes
48answers
1.3m views

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 "@...
740
votes
9answers
1.2m 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 ...
680
votes
20answers
716k 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+?
664
votes
16answers
434k 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 ...
640
votes
14answers
755k 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 ...
630
votes
14answers
60k 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 ...
612
votes
38answers
779k 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?
566
votes
20answers
556k 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) ...
560
votes
17answers
353k 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 ...
549
votes
26answers
531k 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.
549
votes
23answers
590k 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 ...
504
votes
11answers
144k 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?
488
votes
17answers
432k 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 ...
482
votes
16answers
589k 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)]...
474
votes
47answers
419k 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 ...
463
votes
6answers
156k 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
462
votes
3answers
62k 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 ...
456
votes
22answers
425k 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 ...
452
votes
7answers
254k 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" [...
451
votes
29answers
326k 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 ...
446
votes
14answers
686k 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)]="...
438
votes
5answers
308k 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 ...
427
votes
4answers
740k 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 ...
417
votes
10answers
150k 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....
400
votes
8answers
289k 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/...
392
votes
27answers
210k 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 ...
387
votes
22answers
423k 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', ...
382
votes
25answers
518k 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 ...
380
votes
12answers
248k views

How to bundle an Angular app for production

What is the best method to bundle Angular (version 2, 4, 6, ...) for production on a live web server. Please include the Angular version within answers so we can track better when it moves to later ...
375
votes
22answers
416k views

Angular error: "Can't bind to 'ngModel' since it isn't a known property of 'input'"

I'm using Angular 4 and I am getting an error in the console: Can't bind to 'ngModel' since it isn't a known property of 'input' How can I resolve this?
370
votes
18answers
331k 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 :('; ...
362
votes
18answers
384k views

Angular no provider for NameService

I've got a problem loading a class into an Angular component. I've been trying to solve it for a long time; I've even tried joining it all in a single file. What I have is: Application.ts /// <...
359
votes
13answers
560k 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)="...
359
votes
21answers
487k views

Angular - Set headers for every request

I need to set some Authorization headers after the user has logged in, for every subsequent request. To set headers for a particular request, import {Headers} from 'angular2/http'; var headers = ...
357
votes
37answers
413k views

NPM Install Error:Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'

When creating a new Angular 5 project: node version: 8.9.2 npm version: 5.5.1 My Command is: npm install -g @angular/cli The Error is: npm ERR! **Unexpected end of JSON input while parsing near '......
353
votes
26answers
385k views

Angular 4: no component factory found,did you add it to @NgModule.entryComponents?

I'm using Angular 4 template with webpack and I have this error when I try to use a component (ConfirmComponent): No component factory found for ConfirmComponent. Did you add it to @NgModule....
352
votes
31answers
295k views

In Angular, how do you determine the active route?

NOTE: There are many different answers here, and most have been valid at one time or another. The fact is that what works has changed a number of times as the Angular team has changed its Router. The ...
347
votes
16answers
229k views

Angular EXCEPTION: No provider for Http

I am getting the EXCEPTION: No provider for Http! in my Angular app. What am I doing wrong? import {Http, Headers} from 'angular2/http'; import {Injectable} from 'angular2/core' @Component({ ...
346
votes
18answers
208k views

Angular CLI SASS options

I'm new to Angular and I'm coming from the Ember community. Trying to use the new Angular-CLI based off of Ember-CLI. I need to know the best way to handle SASS in a new Angular project. I tried ...
346
votes
3answers
355k 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/...
343
votes
39answers
405k 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&...

1
2 3 4 5
5291