Angular 6 - The exporting of the ForkJoin member is non-existent

After upgrading to Angular 6, I attempted to implement ForkJoin in my project. In my service file, I included the following code:

import { forkJoin } from 'rxjs/observable/forkJoin';

However, it seems to be unable to recognize it and I encountered this error message:

...ForkJoin has no exported member

Is there a way to resolve this issue?

Answer №1

Make a simple adjustment to your import statement -

import {forkJoin} from 'rxjs';

Rxjs 6 has introduced easier import paths and more user-friendly operator methods, eliminating the need for using the Observable patch.

Instead of using:

return Observable.forkJoin( this.http.get('jsonplaceholder.typicode.com/posts'), this.http.get('jsonplaceholder.typicode.com/users') ); 

You can now simply write:

return forkJoin(this.http.get('jsonplaceholder.typicode.com/posts'), this.http.get('jsonplaceholder.typicode.com/users'));

I hope you find this information helpful!

Answer №2

RxJS 6 introduces new and simplified import paths, eliminating chainable operators in favor of pipeable operators. This structural change enhances the library's overall tree-shakability, resulting in smaller bundle sizes.

To ensure compatibility, update your imports as shown below:

import { forkJoin } from 'rxjs';

Here are a few more examples of using RxJS when upgrading to Angular:

// Creation and utility methods
import { Observable, Subject, pipe } from 'rxjs';
// Operators now sourced from `rxjs/operators`
import { map, takeUntil, tap } from 'rxjs/operators';

Source: Upgrading and Summary of New Features

Answer №3

service.ts:

   import { HttpClient } from '@angular/common/http';
   import {forkJoin} from 'rxjs';

   constructor(private http: HttpClient) { }
   fetchDetails(){
    let url1 ="../assets/sample.json";
    let url2 ="../assets/sampledata.json";
    //return this.http.get(url);
    return forkJoin(this.http.get(url1),
     this.http.get(url2));  
   }

component.ts:

import { Component,OnInit } from '@angular/core';
import { CommonServiceService } from './common-service.service';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  secondData: any;
  title = 'app';
  myData:any;
  constructor(private service: CommonServiceService) {} 
  ngOnInit(){

    this.service.fetchDetails().subscribe(response=>{
      this.myData= response[0];
      console.log(this.myData);
      this.secondData = response[1];
      console.log(this.secondData);
    })
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Storing user input as an object key in typescript: A comprehensive guide

When delving into Firestore for the first time, I quickly learned that the recommended modeling approach looks something like this: check out the model here members { id: xyz { name: Jones; ...

Mastering Light and Camera Selection in Three.js

Question, In the editor found at this link, you can click on a light or camera to select it. I am familiar with using raycaster.intersectObjects(objects) to select meshes, but how can I achieve the same result for lights and cameras which do not have mesh ...

The argument representing 'typeof Store' cannot be assigned to the parameter representing 'Store<AppState>'

I'm encountering an issue while trying to expand a service in Angular that utilizes ngrx. The error message I'm receiving is as follows: Argument of type 'typeof Store' is not assignable to parameter of type 'Store<AppState>& ...

When trying to console log a selected date, the output displays as undefined

<div class='col-sm-6'> <input [(ngModel)]="date" id="date" name="date" class="form-control" required/> </div> $(function () { $('#date').datetimepicker({ format: 'DD/MM/YYYY hh:mm' } ...

Updating an array using `setState` does not result in the array being updated

I created a component that uses the .map() method to render an array of students and has a button to shuffle and update the display. However, I'm facing an issue where the display does not update every time I click the button. const Home: NextPage = ...

Developing a front-end Angular application with a back-end C# API to handle posting of form data, including files

Seeking assistance with understanding how to upload a file (FormData) and an object from Angular to C# API. It seems that the HttpClient post method can only accept one body parameter, so I am unable to post both the FormData object and the SomeObject obje ...

What is the process for executing a particular NPM command prior to building in ASP.NET Core?

I need to execute a specific NPM command for Angular within my ASP.NET Core application. The command is simple, it just prepares some files. Is there a way to automate running the NPM script before each build in ASP.NET Core? The Angular app is located i ...

The Typescript "and" operator is used for combining multiple conditions

I'm having difficulty understanding the functionality of the & operator in TypeScript. I recently encountered this code snippet: type IRecord<T> = T & TypedMap<T>; Can someone explain what this operator does and how it differs fr ...

Is it possible to configure the JSONP module in Angular 2 to specifically interpret the MIME type as 'application/json'?

I am currently utilizing the JSONP module to call a SonarQube API. this.jsonp.get('https://sonarqube.com/api/projects/index') .subscribe(res => console.log(res)); In the past, I used the Http module of Angular2, however, this led to the ...

Exporting custom type definitions using a node module

In my project, I have a module named module_core with a specific directory structure as shown below: /src /company /webservices /service-one ... /service-two ... /service-new // my service i ...

Angular version 4 JSONP request callback

Currently, I am working on the migration of an Angular 1 application to Angular 4. One particular challenge I have encountered is a jsonp call to an endpoint over which I have no control. In the Angular 1 app, the following code snippet is being used: js ...

The powerful combination of Visual Studio 2015, TypeScript, Cordova, Angular 2, and System

I am encountering an issue with the loading of external modules using systemJS. I have created a small sample project for VS2015. Feel free to check out the code here: https://github.com/dbiele/TypeScript-Cordova-SystemJS After building the project and at ...

Exploring the Magic of Class Variable Destructuring in React

Is there a simpler method to break down a prop object and assign them to variables of the same name in the class? I am familiar with ({ first: this.first, second: this.second, } = props) however, it can get complicated when dealing with numerous variable ...

Encountering an error message stating "Cannot access 'color' property of undefined" while setting up HighCharts in my xx.ts file

I am new to incorporating highcharts into my project and struggling with it. Despite following documentation and trying various methods, I have not been able to make it work as intended. My multi-series high charts were functioning properly until I decide ...

Assigning a custom class to the cdk-overlay-pane within a mat-select component is restricted to Angular Material version 10.2.7

I attempted the code below, but it only works for angular material 11. My requirement is to use only angular material 10. providers: [ { provide: MAT_SELECT_CONFIG, useValue: { overlayPanelClass: 'customClass' } } ] There a ...

Mastering the Art of Injecting Objects from the Server

Utilizing Angular Universal, I am serving my Angular application through an Express server. The objective is to embed an environment object (from the server) into my application. To achieve this, I have created an InjectionToken export const ENVIRONMENT ...

Error in Angular FormGroup validation observed while conducting Cypress test

When the formGroup is invalid, a button is disabled. The button only becomes enabled if the conditions below are met: const field = this.formBuilder.group({ fieldType: new FormControl("", [Validators.required]), fieldName: new FormControl("", ...

Having trouble sending HTTP requests in Angular 6

I am currently facing an issue in my Angular application while trying to send an HTTP POST request to a Spring RESTful API. Despite my attempts, I have not been able to succeed and I do not see any error response in the browser console. Below is a snippet ...

The issue of Angular 2.3.1 custom validator promise not resolving

I am currently working on implementing a sign up form in which I need to check if the username is already taken or not. To accomplish this, I have decided to use promises. The structure of my sign-up component is as follows: import { Component, OnInit } f ...

Steps for setting up i18nextStart by including the i

I am working on developing a multilingual app using the i18next package. Unfortunately, I am experiencing issues with the functionality of the package. Below is an example of the i18next file I have been using: import i18n from "i18next"; impor ...