Angular is experiencing a glitch with updating user profiles

Currently, I am working with Angular and spring-boot. I am facing an issue while attempting to update user details from the settings page. When I click on the update button, nothing happens. Can someone please assist me in identifying where the problem lies? If you are wondering if the update function works on the backend, it does work correctly, so the issue must be related to the frontend.

app.routing

{ path: 'profile-update/:id', component: ProfileUpdateComponent },

SignupData

export interface SignUpData {
    id: string;
    username: string;
    email: string;
    nom: string;
    prenom: string;
    telephone: number;
    roles: string[];
    password: string;
    specialite: string;
    adresses: string[];

}

user.service


const API_URL = 'http://localhost:8080/user/';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

adresses: string[];
updateProfile(id: string, userData: SignUpData): Observable<any> {
return this.http.put(API_URL + 'update/' + id, userData, httpOptions);
}

update.component.ts

updateProfile() {
const {adresse1, ...rest} = this.form;
const userData: SignUpData = {...rest,  adresses: [adresse1]};
this.userservice.updateProfile(this.id, userData).subscribe(
data => {
console.log(data);
},
err => {
this.errorMessage = err.error.message;
}
);
}

onSubmit() { 
this.updateProfile();
this.gotoList();   
}

gotoList() {
this.router.navigate(['profile']);
}

user.html

<form
    name="form"
    (ngSubmit)="f.form.valid && onSubmit()"
    #f="ngForm"
    novalidate>
    <div class="form-row">
        <div class="col form-group">
            <label>First name </label>   
            <input type="text" class="form-control" placeholder=""
            name="prenom"
            [(ngModel)]="form.prenom"

            #prenom="ngModel"> 
        </div> <!-- form-group end.// -->
        <div class="col form-group">
            <label>Last name</label>
        <input type="text" class="form-control" placeholder=" "
        name="nom"
            [(ngModel)]="form.nom"

            #nom="ngModel">
        </div> <!-- form-group end.// -->
  </div> <!-- form-row end.// -->


    <div class="form-group">
        <button type="submit" class="btn btn-primary btn-block"> Update </button>
    </div> <!-- form-group// -->      


  </form>

Answer №1

Attach click event to the update button

<input type="submit" (click)="updateProfile()" class="btn btn-primary btn-block"> Update </input>

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

NextJS function utilizes its own references within React and automatically fetches data without the need for an import

I recently purchased this template and I'm trying to figure out which page the code snippet "{getLayout(<Component {...pageProps} />)}" is directed to during the initial load. It seems like it might be a global variable hidden somewher ...

When utilizing makeStyles in @mui, an error may occur stating that property '' does not exist on type 'string'

I am stuck with the code below: const useStyles = makeStyles(() => ({ dialog: { root: { position: 'absolute' }, backdrop: { position: 'absolute' }, paperScrollPaper: { overflow: 'visib ...

Is there a way to identify the accurate or incorrect array element and modify the component color accordingly?

Upon reviewing the question alternatives, I encountered a problem where clicking on one of the buttons correctly indicated whether it was the correct or incorrect answer by changing its color. However, the issue is that all buttons are being affected by th ...

warning TS2322: Cannot assign type 'PropUser | null' to type 'PropUser'

Issue: Error: src/app/user/containers/shell-user-profile/shell-user-profile.component.html:1:20 - error TS2322: Type 'PropUser | null' is not assignable to type 'PropUser'. Type 'null' is not assignable to type 'Pro ...

Angular BehaviorSubject is not refreshing quickly enough

After following a tutorial on creating full Angular + JWT Authentication, I encountered some issues when testing the project. In order to notify the AuthGuard that I am connected and can proceed to the next page upon logging in, I needed to send the API re ...

Error message "After the upgrade to Angular 15, the property 'selectedIndex' is not recognized in the type 'AppComponent'."

My Ionic 6 app with capacitor has been updated in the package.json file. These are the changes: "dependencies": { "@angular/common": "^15.1.0", "@angular/core": "^15.1.0", "@angular/forms": "^15.1.0", "@angular/platform-browser": "^15.1. ...

Challenges with implementing asynchronous functions in NestJS controllers

Currently, I am in the process of developing a finance tracker application that involves importing data from a CSV file. The import functionality checks if an entry already exists in the database, adds a specific category to it if not found, and then saves ...

Evaluate the Worth of a Property Established in a Subscription

Currently, I am using Jasmine for testing an Angular application and facing a challenge in testing the value of a property that is set within the subscribe call on an Observable within the component. To illustrate this point, I have created an example comp ...

Extract JSON values based on a given condition

I am working on a Typescript project that involves an array and a JSON object. I need to extract the value of a property from the object based on another property's value being in the array. Here is the array: let country: string[] = [ 'AR' ...

Issue with primeng dropdown not displaying the selected label

When using the editable dropdown with filter feature from PrimeFaces, I've noticed that selecting an option displays the value instead of the label. https://i.sstatic.net/8YFRa.png Here is the code snippet: <div class="col-md-5 col-xs-1 ...

Derive a subset Union from a Union in Typescript

Here is a scenario with a Union type I'm working with; type MyUnionType = 'foo' | 'bar' | 'baz' What I need to do is create a new Union called MySubUnion, which will be a subset of the original; type MySubUnion = &apos ...

AngularFire2 - Deleting an item with Observable - Issue with last item not being removed from the User Interface

When I execute this function, the item is deleted from my Firebase database. However, in my Angular 2 app, when it reaches the last entry, it removes it from the database but does not remove it from the list displayed in my *ngFor loop. Strangely, upon ref ...

Is there a way to load a JSON file into an Angular component using axios?

After generating an Angular 5 app using ng-cli, I created the following component: import {Component} from '@angular/core'; import axios from 'axios'; @Component({ selector: 'app-root', templateUrl: './app.component ...

What do you think about gulp-typescript and the latest @types typings for TypeScript?

I've added @types/jasmine as a development dependency. This is my gulp task for compiling TypeScript: gulp.task('compile:tests', ['compile:typescript', 'clean:tests'], function () { var project = ts.createProject(&a ...

When attempting to import the image path from a JSON file, a ReferenceError occurs stating that the data variable is not

I'm currently attempting to iterate through image paths in a JSON file and display them in a browser using the "img" tag. While hardcoded values work perfectly fine, I encountered an issue when trying to switch to a variable as outlined in this post: ...

Issue: The module '@nx/nx-linux-x64-gnu' is not found and cannot be located

I'm encountering issues when trying to run the build of my Angular project with NX in GitHub Actions CI. The process fails and displays errors like: npm ERR! code 1 npm ERR! path /runner/_work/myapp/node_modules/nx npm ERR! command failed npm ERR! c ...

Navigating Through the Angular Migration Journey

As I was researching how to integrate ES2020 with Angular, I came across the following useful link: https://angular.io/guide/migration-update-module-and-target-compiler-options The document begins by stating "This migration adjusts the target and module s ...

Ways to imitate an export default function

//CustomConfigurator.ts export default function customizeConfig(name: string): string { // add some custom logic here return output; } //CustomUtility.ts import customizeConfig from './CustomConfigurator'; export default class CustomUtility ...

Detecting the check status of a checkbox in react native: a complete guide

I'm currently working on a scenario where I need to implement logic for checking or unchecking a checkbox in React Native. If the checkbox is checked, I want to print one string, and if it's unchecked, I want to print something else. How can I ac ...

Using Angular 2 to Invoke Functions in Different Components

In my code, I am attempting to invoke a function from another component within a component. Here is an excerpt of my constructor logic: constructor( private http: Http, private appComponent: AppComponent ) { this.setUrl(); } setUrl() { i ...