Tips for submitting only the ID in an array using Angular 7 with the ng-multiselect-dropdown feature

Upon submission of this form:

let newRole = this.addForm.value
console.log(this.addForm)

The visual representation of the form can be seen in the image below: https://i.sstatic.net/NGwKz.jpg

When I use console.log(this.addForm.value), the output is as shown in the following image: https://i.sstatic.net/rQXRc.jpg

I aim to only submit the permission_id, which should look like this:

value: (5) [1, 2, 3, 4, 5]

If you have any suggestions, please feel free to share them.

Answer №1

To retrieve a new array containing only the permission_id, simply employ the .map method.

let updatedRoles = this.addForm.value.sp_id.map(value => value.permission_id);

Answer №2

Declare a new variable called `newRole` and set it to the result of mapping through the array `this.addForm.value.sp_id`, extracting only the `permission_id` values.

This method will give you an array containing only the ids.

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

Struggling with implementing setRoot and Push functions in an ionic tabs application

I am encountering some issues with the views in my Ionic tabs app. In addition to the 4 tab pages, I have generated pages for login, register, update profile, and add todo. The root page is defined as rootPage:any = 'LoginPage'; in the app.com ...

Positioning the Datepicker Popup in Angular Material

https://i.sstatic.net/lD54U.png Can someone provide a solution for displaying the popup below the input? It is currently affecting the user interface. Any assistance would be greatly appreciated. ...

Is it possible for Visual Studio 2013 to compile TypeScript files even without node.js installed?

My current setup involves using TypeScript in combination with Visual Studio Code and the tsc CLI with node.js installed. I recently made an interesting discovery about tsc - I always assumed it was a javascript program, but then I started to wonder how ...

Having trouble receiving error messages in Angular 2

In my AuthService, an error message is being thrown as a Business Error. When this error is caught in my LogInComponent, instead of displaying the error message "Login failed Error", it shows "Type object Object" in the console log. Why is this happening a ...

Personalized data based on the language within Next.js

Is there a way to customize Metadata for users based on search engine keywords? To enhance SEO performance on my website, I am working on setting up unique Metadata for the two languages my website supports: English and Portuguese. Specifically, I aim to ...

Exporting a Typescript class from one module and importing it into another module

I am encountering issues with my source tree structure, as outlined below: /project/ |- src/ |- moduleA |- index.ts |- classA.ts (which includes a public function called doSomething()) |- moduleB |- classB.ts Th ...

Tips for incorporating JavaScript modules into non-module files

Learning how to use js modules as a beginner has been quite the challenge for me. I'm currently developing a basic web application that utilizes typescript and angular 2, both of which heavily rely on modules. The majority of my app's ts files ...

Tips for incorporating attributes into a customized Material-UI props component using TypeScript in React

I'm interested in using material-ui with react and typescript. I want to pass properties to the components, but I'm having trouble figuring out how to do it. Currently, I'm working with the react-typescript example from the material-UI repos ...

Error in React.tsx Material UI Tab - Avoid using curly braces "{}" as a data type

Currently, I am working on a React TS project and facing an issue while trying to import the Material UI tabs for scrollable functionality. The specific Tabs/Scrollable Tabs example from Material-UI documentation is what I'm referring to: https://mate ...

What steps can I take to stop a browser from triggering a ContextMenu event when a user performs a prolonged touch

While touch events are supported by browsers and may trigger mouse events, in certain industrial settings, it is preferred to handle all touch events as click events. Is there a way to globally disable context menu events generated by the browser? Alternat ...

What is the best method for resetting the user state to null?

I'm currently utilizing VueX in Nuxt with Typescript. My goal is to set the initial state of my user to null. When I try setting state.authenticatedUser:null, everything works smoothly. However, when I attempt to assign an IAuthenticatedUser type to i ...

Jasmine received an error message stating, "An exception was thrown because the property 'subscribe' of undefined cannot be read."

Recently, I embarked on writing unit tests for an established Angular application using Jasmine. Strangely, approximately half of the time, I encounter the following error: Chrome 72.0.3626 (Mac OS X 10.14.3) ERROR { "message": "An error was thr ...

Link Array Element to [(value)] within Angular

Hey there! I'm currently working with Angular Material and dealing with an Array of products to generate a table in my template. <tbody> <tr *ngFor="let item of productArray | async; let i = index"> Within this loop, I have another l ...

Use the mat-autocomplete filter to emphasize partial string matches in the search results

Is there a way to achieve a filter using mat-autocomplete similar to the one shown in this example: trade input example I am looking to implement functionality where as users type in the trade they are searching for, filters are applied based on partial ...

Can someone give me a thorough clarification on exporting and importing in NodeJS/Typescript?

I am inquiring about the functionality of exports and imports in NodeJS with TypeScript. My current setup includes: NodeJS All written in Typescript TSLint for linting Typings for type definitions I have been experimenting with exports/imports instead o ...

TypeScript's type 'T' has the potential to be instantiated with any type, even if it is not directly related to 'number'

Let's say we have a function that takes a value (for example, number) and a callback function that maps that value to another value. The function simply applies the provided callback: function mapNumber<T>(value: number, mapfn: (value: number) = ...

Tips for concealing a react bootstrap modal while simultaneously executing the save function

When I click on the button with the onClick event set to {this.props.onHide}, the Modal is hidden successfully. However, I also need to execute the save function. When I try calling the save function along with the props, the save function is executed but ...

Leverage the SVG foreignObject Tag within your Angular 7 project

I am currently working with Angular 7 and trying to use the SVG foreignObject to embed some HTML code. However, I am encountering an issue where Angular fails to recognize the HTML tags and throws an error in the terminal. Below is the code snippet: &l ...

AngularFire fails to invoke change detection operations

Currently, I am working on developing an application using AngularFire and Angular 8. However, I have encountered a peculiar issue that I need assistance with. I have created a basic service to encapsulate AngularFireAuth: import { Injectable } from &apo ...

Tips for avoiding flashing elements during an API call loop when data is changing

I am working on a project where I need to display data from a JSON array obtained through an API call in Ionic 5 using RxJS. The API is being called every 5 seconds, causing the data to change frequently. However, the issue is that each time the API is cal ...