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, })
    
  ],
})

https://i.sstatic.net/oVLBg.png https://i.sstatic.net/I9C8J.png

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

Applying specific data types to object properties for precise value identification in Typescript

I've been working on creating a dynamic settings menu in TypeScript using the following data: const userSettings = { testToggle: { title: "Toggle me", type: "toggle", value: false, }, testDropdow ...

What is the method to incorporate type hints for my unique global Vue directives?

When I import or create a directive in an SFC file, I can receive TypeScript hints like this: import vFocus from 'my-custom-component-library'; View demo with ts hints However, if I globally register it in main.ts, the type hints are not availa ...

What is the best way to link function calls together dynamically using RXJS?

I am seeking a way to store the result of an initial request and then retrieve that stored value for subsequent requests. Currently, I am utilizing promises and chaining them to achieve this functionality. While my current solution works fine, I am interes ...

If placed in the same document, will promises be executed sequentially?

Let's say I have a function in one file that returns a promise: public async a():Promise<string>{ return 'hi' } In another file, I use this function like so: await service.a.then( hi =>console.log(hi)).catch(err=>{throw err}); ...

I require adding a new line of information into the database table

I am looking for help with adding data into a table without any user inputs. Specifically, I want to add data by passing them into an array and then be able to call them at the "Add Site" button so that the row is added into the table. Can someone assist m ...

Difficulty Converting Array of Objects to Proper Type with Q.Promise and KO.mapping

I have encountered an issue while trying to filter an observable array. It seems that the ko.utils.arrayFilter method is converting all my model's field names to lowercase, causing unexpected behavior. I should mention that this project involves Types ...

`Unresponsiveness in updating bound property after change in Angular2 child property`

Having trouble with my custom directive and ngOnChanges() not firing when changing a child property of the input. my.component.ts import {Component} from 'angular2/core'; import {MyDirective} from './my.directive'; @Component({ d ...

Employing the Eclipse Palantir TypeScript Plug-in in conjunction with JSPM

I currently utilize the Palantir Eclipse TypeScript Plug-in (v1.8.0.v20160223-1645), which functions flawlessly when my d.ts files are stored in the same source folder /src. However, due to JSPM, these files reside in a different folder now, causing issues ...

The Chart.js graph fails to appear when placed within an ngIf directive

I have encountered an issue with my simple scatter line chart created using Chart.js within a bootstrap panel. It works perfectly fine until I place it inside an ngIf div. Has anyone faced this problem before? Is there a solution to make the chart display ...

ngx-graphs -> ngx-graphs-bar-vertical x-axis labels with multiple lines

I'm using 'ngx-charts' with Angular, and I have encountered an issue with long text on my X axis labels. The text overflows and displays three dots instead of wrapping onto multiple lines. Is there a way to make the text wrap onto multiple l ...

Angular: finding out if Observable or BehaviorSubject has undergone any important modifications

I am facing an issue with my user object in a membership service. I need to ensure that my services are updated only when there are relevant changes in the user object. To determine if there are relevant changes in the user object, I compare it with the ...

Bring in exclusively typescript module declarations

In my various React projects, I find myself constantly declaring the same typescript modules, such as fonts.d.ts: declare module "*.woff"; declare module "*.woff2"; or images.d.ts: declare module "*.jpg" { const src: string ...

The current directory does not belong to a Cordova project

Upon executing ionic cordova run browser --verbose within the main directory of my Ionic4 project, I encounter the error message "Current working directory is not a Cordova-based project." as shown below. I've observed that the command generates a "w ...

Strategies for handling multiple HTTP requests in Angular using RXJS

Within this demonstration application, we have the following structure: A list of articles (loaded upon page initialization) Each article contains a nested object called detail, which is loaded lazily Clicking on an article item will load its details. H ...

Angular Fragmentary Perspective

I have a lengthy form in angular that I am currently working on. I'm wondering if there is a way to divide it into multiple views and then link each of them back to the main view. <div class="container"> <div class="row" id="part1"> ...

Although NgRx retrieves data from the API, it does not save it to the state

I've been struggling to grasp a fundamental concept in implementing ngrx. For instance, I have a situation where I need data from an API to validate information in my component, but once the validation is complete, I no longer need that data stored in ...

Angular 5's recursive directives in dynamic modules without any circular dependencies

I've been experimenting with loading dynamic templates into my Angular 5 app. My first attempt was following the examples in the official Angular documentation, but I quickly realized that they only cover loading static components dynamically. Next, ...

How can you display a loading indicator after a delay using Observables, but make sure to cancel it if the loading is completed

Within my customer-detail component, I have implemented code that achieves the desired outcome. However, I believe there might be a more reactive and observable way to approach this task. Instead of using an if statement to set this.isLoading = true;, is ...

What is the best way to effectively handle the proxying of objects across multiple levels?

As illustrated in a Stack Overflow thread, utilizing Proxy objects is an effective method for monitoring changes in an object. But what if you need to monitor changes in subobjects? In such cases, you will also have to proxy those subobjects. I am curren ...

Encountered an error trying to access '0' property of an undefined object when iterating through data in angular framework

My API is returning data in the format shown below: "fileName": "data.txt", "onlyInFile1": [ { "_id": "60618e87c2077428e4fedde5", "TERMINAL_ID": "Y6152114", "EXTERNAL_STAN": & ...