Search code examples
angularweb-servicesangular-servicesangular-httpclient

Post service is not updating value from Angular front, but it's working in postman


Here is the Request I do in Postman, it works fine, it just send a display value(string) "true"/"false" to enable or disable a tab, and then I check in the get request to get all tabs and see that it change the value of the tab.

enter image description here

The thing is in Angular, I'm sending the values and also getting a 200OK response no error but when I check at the postman get request I have no changes in the tab I disabled or enabled from the front

/**
   * get active tabs
   */
  public getAvailableTabs() {
    return (this.http.get<SiwaTabs[]>(`${ApiProvidersService.CurrentPath()}/Siwa/Settings/SiwaTabs`
    ).map(tabs => tabs.map(t => new SiwaTabs(
      t.id,
      t.title,
      t.route,
      t.UserID,
      t.display
    ))));
  }

  /**
   * set SiwaTabs
   * @param display
   * @param tabsID
   */
  public changeSiwaTabs(display: string, tabsID: number) {
    console.log(display, tabsID)
    return (this.http.post<any>(`${ApiProvidersService.CurrentPath()}/Siwa/Settings/changeSiwaTabs`, {
        display: display,
        tabsID: tabsID
      }
    ).map
    (result => result));
  }

Here is the ts file subscribing to the service

 /**
   * onInit
   * set initial theme
   * */
  ngOnInit() {
    this.getAvailableTabs();
    this.openSetting = "none";
    this.ReadOnlyStyleGuideNotes = true;
    this.Design = this.UserThemes.getTheme(this.User.activeUser.ThemeID);
    this.User.setTheme(this.User.activeUser.ThemeID);
    this.selectLang(this.User.activeUser.LanguageValue);
    this.selectedTabsID(this.Tabs);
    this.spinner = new Spinner();
    this.timedMessage = new TimedMessage();
    let id: number = 2
    let display: string = "true"
    this.User.changeSiwaTabs(display, id).subscribe((res) => {
      console.log(display, id);
      console.log(res.status);
      if (res.status === true) {
        this.timedMessage.show(
          "Die Tabs wurden erfolgreich geändert",
          "alert-success",
          2000
        );
      }
    });
  }

This is the response from web browser: enter image description here enter image description here

What could I did wrong?


Solution

  • It was backend problems with Access-Control-Allow-Origin header