property ‘forkJoin’ does not exist on type ‘typeof observable’ – angular2

Angular 6 changes this up a bit. forkJoin has been converted to a regular function so, instead of: import {Observable} from ‘rxjs/Observable’; … return Observable.forkJoin( this.http.get(‘someurl’), this.http.get(‘someotherurl’)); Use: import {forkJoin} from ‘rxjs’; … return forkJoin( this.http.get(‘someurl’), this.http.get(‘someotherurl’)); You can go to https://www.metaltoad.com/blog/angular-6-upgrading-api-calls-rxjs-6 for more explanation.

Using multiple instances of the same service

Angular DI maintains a single instance per provider. In your case if you have two constructor parameters with the same type, they resolve to the same instance. What you can do is to provide a factory function (different from a simple useFactory provider event though it uses it as well) (Example copied from https://stackoverflow.com/a/37517575/217408) { … Read more

How can I watch for changes to localStorage in Angular2?

The key thing is to use window.addEventListener(“storage”, . While the library probably does it the “right” way for angular, here is a “light” version I put together, using .bind(this) instead of mucking about in angular’s internals. import { Injectable, OnDestroy } from ‘@angular/core’; import { Subject } from ‘rxjs/Subject’; import { share } from ‘rxjs/operators’; … Read more

Can lazy-loaded modules share the same instance of a service provided by their parent?

Using a forRoot, as mentioned here, is what you need probably. The problem it’s meant to solve, is directly related to the problem you are experiencing with lazy loaded modules getting their own service. It’s explained here in Configure core services with forRoot, but that section doesn’t explain about the lazy-loading issue. That is explained … Read more

How I add Headers to http.get or http.post in Typescript and angular 2?

You can define a Headers object with a dictionary of HTTP key/value pairs, and then pass it in as an argument to http.get() and http.post() like this: const headerDict = { ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’, ‘Access-Control-Allow-Headers’: ‘Content-Type’, } const requestOptions = { headers: new Headers(headerDict), }; return this.http.get(this.heroesUrl, requestOptions) Or, if it’s a POST request: … Read more

How to share service between two modules – @NgModule in angular not between to components?

As per the final version of Angular 2, services provided by a module are available to every other module that imports it. The Official Style Guide advice that application-wide services (singletons) that are to be reused anywhere in the application should be provided by some Core Module, that is to be imported in the main … Read more

How to config different development environment in Angular 2 app

Short answer: use Angular CLI. It is in beta stage but works really well and it’s recommended by the Angular Team for starting new projects. With this tool you can configure different environments. At build time, the src/client/app/environment.ts will be replaced by either config/environment.dev.ts or config/environment.prod.ts, depending on the current CLI environment. Environment defaults to … Read more

Why we should use RxJs of() function?

The reason why they’re using of() is because it’s very easy to use it instead of a real HTTP call. In a real application you would implement getHeroes() like this for example: getHeroes(): Observable<Hero[]> { return this.http.get(`/heroes`); } But since you just want to use a mocked response without creating any real backend you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)