Angular/NGRX disrupts the result

Currently, I am working on a piece of code where my main focus is to add a reducer to the module. Here's the snippet:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import {Action} from '@ngrx/store';
import { Component } from '@angular/core';

class Book {
  id: number;
  name: string;
}

class BookStore {
  books: Book[];
}

const ADD_BOOK = '[Book] Add book'; 

export function addReducer(state = BookStore, action: Action) {
  console.log(state, action);

  switch (action.type) {

  }
}

@Component({
  selector: 'app-root',
  template: '<h1>Hello!</h1>',
})

export class AppComponent {
  title = 'app';
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    StoreModule.forRoot({ count: addReducer })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

However, upon adding this line of code:

StoreModule.forRoot({ count: addReducer })

The content of my page disappears, including the 'Hello!' message, and oddly no errors are shown in the console.

Here are the versions of libraries that I'm currently using:

  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "@ngrx/effects": "^6.1.0",
    "@ngrx/store": "^6.1.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },

I am trying to understand what could be causing this issue. Do you think I might need to make some additional modifications to my reducer?

Answer №1

Appreciate it. Once I updated angular to the latest version, everything started working smoothly.

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

Transforming Javascript into Typescript with node modules in Visual Studio 2015

After developing a JavaScript web app using npm and webpack, I successfully converted all the .js files to .ts using the PowerShell command found here. Now, I am looking to transition to a VS2015 TypeScript project but struggling to find guidance on how ...

Navigating a Laravel application with Angular 7: A comprehensive guide

Setting up a local server with LAMP, I am incorporating Laravel for the backend and Angular 7 for the frontend. Included in my web.php file is: <?php /* |-------------------------------------------------------------------------- | Web Routes |------ ...

Issue a tslint warning when mockResolvedValueOnce is used with async/await

While working with the request-promise module, everything seems to be functioning correctly except for a warning from tslint. Below is my unit test: import * as request from 'request-promise'; jest.mock('request-promise', () => { ...

Referring to a component type causes a cycle of dependencies

I have a unique situation where I am using a single service to open multiple dialogs, some of which can trigger other dialogs through the same service. The dynamic dialog service from PrimeNg is being used to open a dialog component by Type<any>. Ho ...

Checking the alignment of celestial bodies for an array of entities

Seeking to implement validation for a form featuring checkbox selections with corresponding number inputs. When a user selects a profession checkbox, they must enter the number of years of experience they have in the input next to it. The array structure i ...

Updating Time by Adding Minutes using ngFor Loop in Angular 4

I'm currently developing a scheduler that requires user input for start time and the time between two games. I am looking to display the time in a loop using ngFor, incrementing by minutes each time. How can I accomplish this within an Angular 4 HTML ...

When trying to access a certain class property, I was met with the following error message: TypeError: Unable to read/set property 'x' of

Lately, I've delved into the realm of JavaScript / TypeScript and decided to create a basic React App using TypeScript. Within one of my components, I aim to switch between different components using a "state" (where each component will follow the pre ...

"Utilizing a background image within a component to completely cover the entirety

Hey everyone, I need some help with a confusing issue. I'm currently working on an AngularJs project and I am struggling to set a background image for a specific component without affecting the entire application. My goal is to have the image cover t ...

Images failing to load on a webpage built with HTML

I am experiencing an issue where the image does not display on the page, even though I have verified that the image file exists. Below is my code: <h3>Employees Directory</h3> <div class="row"> <div *ngFor="let randomdata of randomdat ...

Utilize Knex to retrieve data from the req.query

express and knex have been giving me some trouble; I am struggling to get this endpoint working using req.querys (response from express), even though it worked fine when I used req.params. Express: app.get(`/actor`, async (req: Request, res: Response) =&g ...

Adjust the width of a div in Angular 6 based on a specified condition

I need to adjust the width of a div based on certain conditions. <div [ngStyle]="'width': selectedTab =='Home' ? '50%' : '100%'"> </div> The currently selected tab is stored in "selectedTab". There ...

Angular 7 is taking an unusually long time to load the after login component

Upon logging into my Angular 7 application, the after-login component experiences slow loading for the first time. However, if a user logs out and then logs back in without closing the browser, the speed improves. The routing structure is as follows: In ...

Angular 7: Separate Views for Search Bar and Results

Two components have been developed: search-bar.component.ts: displayed in all views search.component.ts: responsible for displaying the results (response from a REST API) The functionality is as follows: whenever I need to perform a global search (produ ...

The observable of type 'any' does not contain the property 'subscribe'

When trying to extract data from googleTagmanger, I encountered an error stating that "Property 'subscribe' does not exist on type 'Observable'". Below is the code snippet I used: this.translate.get('newtest.testsimulation'). ...

Issue with Loosing Focus in React TextInput when typing the letter "S"

My TextInput is acting strangely - it loses focus only when I type the letter s. All other letters work fine. <FormControl key={"1"} sx={{ m: 1 }} variant="outlined" onChange={handleFilterValueChange}> <InputLabel htmlFor=& ...

What is the best way to obtain and display a PDF file (DocumentViewer) within an Ionic 5 application?

I watched a YouTube tutorial on how to open a PDF viewer. The PDF file is located in the assets folder, which is saved under the app folder. I attempted multiple file paths (let filePath = this.file.applicationDirectory + 'public/assets/';) but s ...

Creating an object instance in Angular 2 using TypeScript

Looking for guidance on creating a new instance in TypeScript. I seem to have everything set up correctly, but encountering an issue. export class User implements IUser { public id: number; public username: string; public firstname: string; ...

The Gatsby Head API is experiencing issues with correctly formatting scripts

I'm currently exploring the use of Gatsby's Head API with Gatsby.js (4.24.2) and TypeScript, and I am encountering some inconsistent outcomes. Here is the code I am working with, it is functional but certain scripts are failing to compile: const ...

What methods does Angular use to differentiate between router-outlet tags that are located in various components?

Within the app.component.html, we include a < router-outlet > tag that dynamically loads other modules, components, and views. However, if we have a second component (imported in a different module) with its own < router-outlet > How does Ang ...

No type checking errors present in React Typescript

I've come across a peculiar issue with React and TypeScript. After running npm start or npm build, I'm not seeing any errors. In the code snippet below, I intentionally assign invalid values to function arguments and variables, but strangely, the ...