In order to address the issue of displaying a 404 error in In-Memory Angular,

I have watched all the videos regarding the In-memory web API and diligently followed all the steps and instructions. However, I am still encountering a 404 Error. Please inform me if I missed something or made an error. I have attempted to troubleshoot and conduct research on this matter, but unfortunately, my efforts have proven unsuccessful.

MY .TS

    this.serialForm = this.fb.group({
      id:[0],
      itemCode:['', Validators.required],
      qtyReceived:[0, Validators.required],
      inputs: this.fb.array([this.CreateArray()]),
    });
    this.serialForm.get('qtyReceived').valueChanges.subscribe((res) => {
      for (let i = this.displayArray.length; i < res; i++) {
        this.displayArray.push(this.CreateArray());
        console.log(this.displayArray);
      }
    });
    this.dataValues = this.serialForm.get('qtyReceived').setValue(this.data.qtyReceived),
    this.dataValues = this.serialForm.get('itemCode').setValue(this.data.propertyNo)
  

  }

  get displayArray():FormArray{
    return this.serialForm.get('inputs') as FormArray;
  }
  CreateArray():FormGroup{
    return new FormGroup({
      serialNum: new FormControl('', {validators: [Validators.required]}),
    });
  }
  onSave(): void {
   if(this.serialForm.valid){
    this.service.add(this.serialForm.value).subscribe((res)=>{
      console.log(res)
    })
   }
  }

HTML

<mat-dialog-content>
  <form [formGroup]="serialForm">
    <mat-form-field class="full-width" floatLabel="always" appearance="outline" [hidden]="true">
      <mat-label>Id</mat-label>
      <input matInput type="text" formControlName="id">
    </mat-form-field>
    <div class ="row">
      <div class="col">
        <mat-form-field class="full-width">
          <mat-label>Item</mat-label>
          <input matInput type="text" formControlName="itemCode" readonly="true">
        </mat-form-field>
      </div>
      <div class="col-sm-2">
        <mat-form-field class="full-width">
          <mat-label>Serial Per Qty</mat-label>
          <input matInput type="number" formControlName="qtyReceived" readonly="true">
        </mat-form-field>
      </div>
    </div>
    <div
      *ngFor="let addressGroup of serialForm.get('inputs')['controls']; let i = index"
      [formGroup]="addressGroup"
    >
      <div class="row">{{i + 1}}<div> <input type="text" formControlName="serialNum" style="width:685px"></div>
      </div>
    </div>


    <div class="d-flex justify-content-center button-row">
      <button mat-raised-button color="primary" class="button" (click)="onSave()" [disabled]="serialForm.invalid">
        <mat-icon>check_circle_outline</mat-icon>
        {{actionBtn}}
      </button>
      <button mat-raised-button color="warn" class="button">
        <mat-icon>clear_all</mat-icon>
        Clear
      </button>
    </div>
  </form> 

When using In-Memory Web Api, I tried using the console.log(user) command but it did not show up in my console. Is this normal or do I need to make some adjustments?

@Injectable({
  providedIn: 'root'
})
export class InMemoryDataService implements InMemoryDbService {
  createDb() {
    const users = [ 
      { id: 11, itemCode: 'ICT000000211', qtyReceived:0, inputs:[{
        serialNum:'string'
      }] },
      { id: 12, itemCode: 'ICT000000212', qtyReceived:0, inputs:[{
        serialNum:'string'
      }] },
      { id: 13, itemCode: 'ICT000000213', qtyReceived:0, inputs:[{
        serialNum:'string'
      }] },
      { id: 14, itemCode: 'ICT000000214', qtyReceived:0, inputs:[{
        serialNum:'string'
      }] },
      { id: 15, itemCode: 'ICT000000215', qtyReceived:0, inputs:[{
        serialNum:'string'
      }] },
      { id: 16, itemCode: 'ICT000000216', qtyReceived:0, input:[{
        serialNum:'string'
      }] },
    ];
    console.log(users)
    return { users };
  }
}

Services

export class SerialCodeService {
private tempUrl = 'api/users';
  constructor(private http: HttpClient, private appsetting:AppSettings) { }

  getHeroes(){
    return this.http.get(this.appsetting.baseURL + 'users')
  }
  /** POST: add a new hero to the database */
  add(data:any) {
    return this.http.post(this.appsetting.baseURL + 'users', data)
  }

MODEL

import { serialDTO } from "./serialDTO";

  export class SerialCodeDTO {
    id:number
    itemCode:string
    qtyReceived:number
    inputs:serialDTO[];
  }

export class serialDTO {
     serailNum:string
  }

Module

 MatTreeModule,
    MatSortModule,
    NgxMatSelectSearchModule,
    SelectDropDownModule,
    HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, { 
    dataEncapsulation:false, })
    
  ],
})

Answer №1

Make sure that your function createDb() is returning an Object instead of an array.

The correct syntax for return { users } should be :

return { users : users };

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

What kind of Input field is being provided as an argument to a TypeScript function?

Currently, I am working through an Angular 2 tutorial where an input element is being passed to a function through a click event. The tutorial includes an addTodo function with the following signature: addTodo(event, todoText){ }. However, there is a warn ...

Experiencing difficulty creating query files for the apollo-graphql client

I'm currently attempting to learn from the Apollo GraphQL tutorial but I've hit a roadblock while trying to set up the Apollo Client. Upon executing npm run codegen, which resolves to apollo client:codegen --target typescript --watch, I encounter ...

Utilize multiple activated modules in Angular 2

Recently, I've been exploring the new features of Angular 2 final release, particularly the updated router functionality. An interesting example showcasing the router in action can be found at this link: http://plnkr.co/edit/mXSjnUtN7CM6ZqtOicE2?p=pr ...

The issue of ExpressionChangedAfterItHasBeenCheckedError is a common problem faced by Angular

I have implemented a component loading and an interceptor to handle all requests in my application. The loading component is displayed on the screen until the request is completed. However, I am encountering an error whenever the component inside my router ...

Having trouble getting the npm package with @emotion/react and vite to function properly

Encountering an issue with the npm package dependencies after publishing, specifically with @emotion/react. This problem arose while using vite for packaging. Upon installing the package in another project, the css property appears as css="[object Ob ...

Utilizing localstorage data in angular 2: A comprehensive guide

Is there a way to utilize data stored in localstorage for another component? This is what the localstorage service looks like: localStorage.setItem('currentUser', JSON.stringify({ username: username, token: success, res: res.data })); I am inte ...

Can you explain the distinction between using tsserver and eslint for linting code?

As I work on setting up my Neovim's Native LSP environment, a question has arisen regarding JS/TS linter. Could someone explain the distinction between tsserver and eslint as linters? I understand that tsserver is a language server offering features ...

Adding a blank line in an Angular table using primeNG to display database information requires a specific method

In my Angular application, I am utilizing primeNG table to display data fetched from a database. The table comes with 'add' and 'delete' buttons for user interaction. To view the interface, click on this link: https://i.stack.imgur.com/ ...

Instead of showing the data in the variable "ionic", there is a display of "[object object]"

Here is the code snippet I'm working with: this.facebook.login(['email', 'public_profile']).then((response: FacebookLoginResponse) => { this.facebook.api('me?fields=id,name,email,first_name,picture.width(720).height( ...

Ways to invoke main.ts to communicate with an Angular component using Electron

I have a good understanding of how to communicate between an angular app and the electron main thread using IPC. However, in my current scenario, I have threads running in the electron main thread for video processing. After these threads complete their t ...

Warnings during npm installation such as incorrect version numbers and missing descriptions

There are some warnings appearing in the command line that I need help with: $ npm install npm WARN Invalid version: "x.0.0" npm WARN myFirstAngular2Project No description npm WARN myFirstAngular2Project No repository field. npm WARN myFirstAngular2Projec ...

Utilizing Angular 2 alongside ngrx/store for seamless updates to specific properties within the state object without disrupting the entire structure

I am facing an issue where I need to update a property of a state object without creating a new object. Is there a way to add or update a single property without replacing the entire object? Below is the reducer code: const initialState = { all: [], ...

What is the process for implementing an abstract factory pattern in Typescript?

I’m currently facing a challenge while attempting to incorporate a standard abstract factory pattern in Typescript, only to find that the compiler is not quite on board with my efforts. Below is a simplified version of the code I am working with: abstra ...

How can I customize a Vue component slot in Storybook 8.0.6 using Vue 3.4 and Typescript to display various subcomponents within a story?

Incorporating a variety of sub-components into my Vue 3 component based on context is proving to be a challenge. Utilizing slots seems to be the solution in Vue 3, but I'm struggling to make it work within Storybook 8, which I'm using to showcase ...

How can I apply concatMap in Angular?

Can you please guide me on how to effectively utilize concatMap with getPrices() and getDetails()? export class HistoricalPricesComponent implements OnInit, OnDestroy { private unsubscribe$ = new Subject < void > (); infoTitle ...

What is the correct way to nest multiple ng-if statements?

I'm currently grappling with a problem involving multiple nested ngIf directives applied to ng-template elements in Angular.js, and I've yet to find the ideal solution. While I am aware of workarounds, they are not as efficient as I would like th ...

Import resolves Uncaught ReferenceError by preventing access to 'xx' before it is initialized

Currently, I am troubleshooting a peculiar error that has come up. Within my service file where all other services are stored, I have included the import of one component along with all the other services required by the frontend. import { VacationComponen ...

What is the best way to implement a dynamic mask using imask in a React

I have a question regarding the implementation of two masks based on the number of digits. While visually they work correctly, when I submit the form, the first mask is always selected. How can I resolve this issue? My solution involves using imask-react ...

having difficulty applying a border to the popup modal

Currently, I am utilizing a Popup modal component provided by the reactjs-popup library. export default () => ( <Popup trigger={<button className="button"> Guide </button>} modal nested > {(close: any) =&g ...

Utilizing Azure Function Model v4: Establishing a Connection with Express.js

Using Model v4 in my Azure function index.ts import { app } from "@azure/functions"; import azureFunctionHandler from "azure-aws-serverless-express"; import expressApp from "../../app"; app.http("httpTrigger1", { methods: ["GET"], route: "api/{*segme ...