How to use angular2 built-in date pipe in services and directives script files [duplicate]

Since CommonModule does not export it as a provider you’ll have to do it yourself. This is not very complicated. 1) Import DatePipe: import { DatePipe } from ‘@angular/common’; 2) Include DatePipe in your module’s providers: NgModule({ providers: [DatePipe] }) export class AppModule { } or component’s providers: @Component({ selector: ‘home’, styleUrls: [‘./home.component.css’], templateUrl: ‘./home.component.html’, … Read more

What is the difference between the $parse, $interpolate and $compile services?

Those are all examples of services that aid in AngularJS view rendering (although $parse and $interpolate could be used outside of this domain). To illustrate what is the role of each service let’s take example of this piece of HTML: var imgHtml=”<img ng-src=”https://stackoverflow.com/path/{{name}}.{{extension}}”>” and values on the scope: $scope.name=”image”; $scope.extension = ‘jpg’; Given this markup … Read more

The view is not updated in AngularJS

You are missing $scope.$apply(). Whenever you touch anything from outside of the Angular world, you need to call $apply, to notify Angular. That might be from: xhr callback (handled by $http service) setTimeout callback (handled by $defer service) DOM Event callback (handled by directives) In your case, do something like this: // inject $rootScope and … Read more

Angular: ‘Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays’

As the error messages stated, ngFor only supports Iterables such as Array, so you cannot use it for Object. change private extractData(res: Response) { let body = <Afdelingen[]>res.json(); return body || {}; // here you are return an object } to private extractData(res: Response) { let body = <Afdelingen[]>res.json().afdelingen; // return array from json file … Read more

AngularJS – UI Router – programmatically add states

See -edit- for updated information Normally states are added to the $stateProvider during the config phase. If you want to add states at runtime, you’ll need to keep a reference to the $stateProvider around. This code is untested, but should do what you want. It creates a service called runtimeStates. You can inject it into … Read more

use $http inside custom provider in app config, angular.js

The bottom line is: You CANNOT inject a service into the provider configuration section. You CAN inject a service into the section which initializes the provider’s service. Details: Angular framework has a 2 phase initialization process: PHASE 1: Config During the config phase all of the providers are initialized and all of the config sections … Read more

Angular 2: Two backend service calls on success of first service

You need to leverage the flatMap operator to call one request after the previous one completed: this.service.getUserInterests().flatMap( (interests) => { let params: URLSearchParams = new URLSearchParams(); params.set(‘access_token’, localStorage.getItem(‘access_token’)); return this.http.get(‘http://localhost:8080/user/selections’, { search: params }).map((res: Response) => res.json()); } ); When subscribing to this data flow, you will only receive the result of the last request. … Read more