Storing a value retrieved from a GET method in Angular 2

I have a query regarding Angular 2. I am new to this framework and I attempted to store a simple value in a variable by calling a get method that retrieves a number from the backend written in C#. How can I save this returned value in a global variable?

getTarea(a,b,c,d,e){
        return this._http.get('http://localhost:50790/ApiProductoTipo/TareaPT?delegacionId='+a+'&municipioId='+b+'&ejercicioId='+c+'&ninternoId='+d+'&tipo='+e)
             .map(res=> {alert('Tarea:'+res);})
            .catch(this.handleError);
    }

This snippet displays

Tarea:Response with status: 200 OK for URL: http://localhost:50790/ApiProductoTipo/TareaPT?delegacionId=11&municipioId=1&ejercicioId=2017&ninternoId=-1&tipo=T

However, my requirement is to obtain the numerical value returned by this method. Any suggestions on how to achieve this?

Back

[HttpGet]
public int GetTareaPT(int delegacionId, int municipioId, int ejercicioId, int ninternoId, string tipo)
{
    int numtarea = this.productoTipoService.GetTareaPT(delegacionId, municipioId, ejercicioId, ninternoId, tipo);

    if (numtarea != 0)
    {
        return numtarea;
    }
    else
    {
        return 0;
    }
}

Answer №1

Big appreciation to AJT_82 for solving the problem

.map(res=> {alert('Task:', res.json());})

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

Issue with displaying Ng-x spinner in Angular 5 function

Have you ever encountered this issue before? I've noticed that ngx-spinner doesn't work when used within a function, but it works fine when placed inside the subscribed callback. When placed outside of the authservice, the spinner isn't dis ...

Setting IDPs to an "enabled" state programmatically with AWS CDK is a powerful feature that allows for seamless management of

I have successfully set up Facebook and Google IDPs in my User Pool, but they remain in a 'disabled' state after running CDK deploy. I have to manually go into the UI and click on enabled for them to work as expected. How can I programmatically e ...

What are the reasons for the inability to send form-data in Postman?

Encountering an issue when trying to send form-data in postman as Sequelize returns an error: value cannot be null However, everything works fine when sending a raw request with JSON. Have tried using body-parser and multer, but no luck. This is my inde ...

Troubleshooting: Angular add/edit form issue with retrieving data from a Span element within an ngFor loop

I am currently working on an add/edit screen that requires submitting a list, among other data. The user will need to check 2-3 checkboxes for this specific data, and the saved record will have multiple options mapped. Here is what the HTML looks like: &l ...

Creating regex to detect the presence of Donorbox EmbedForm in a web page

I am working on creating a Regex rule to validate if a value matches a Donorbox Embed Form. This validation is important to confirm that the user input codes are indeed from Donorbox. Here is an example of a Donorbox EmbedForm: <script src="https: ...

Set a timeout for a single asynchronous request

Is there a way to implement a setTimeout for only one asynchronous call? I need to set a timeout before calling the GetData function from the dataservice, but it should be specific to only one asynchronous call. Any suggestions? Thank you. #html code < ...

Transcompiling TypeScript for Node.js

I'm in the process of developing a Node project using Typescript, and I've configured the target option to es6 in my tsconfig.json file. Although Node version 8 does support the async/await syntax, Typescript automatically converts it to a gener ...

Problem with Typescript and packages.json file in Ionic 3 due to "rxjs" issue

I encountered a series of errors in my Ionic 3 project after running ionic serve -l in the command terminal. The errors are detailed in the following image: Errors in picture: https://i.sstatic.net/h3d1N.jpg Full errors text: Typescript Error ';& ...

What is the best way to emphasize when the path matches exactly with '/'?

Is there a way to highlight the path only when it exactly matches '/'? Currently, even on 'Page 2', the 'Home' link is still highlighted. Check out the plunker here .active { color: red; } <a routerLinkActive="active" r ...

Unable to locate the name 'JSON' in the typescript file

I have been working on an angular application where I have implemented JSON conversion functionalities such as JSON.stringify and JSON.parse. However, I encountered an error stating 'Cannot find name 'JSON''. Furthermore, there is anoth ...

Issue in Angular 4 unit test: Unable to access 'injector' property due to its null value

I have the following test (using karma and jasmine). Please note that I call initTestEnvironment elsewhere, but I have verified that it gets called (with a console.log). Every time I run it, I encounter: TypeError: Cannot read property 'injector&apos ...

Sorting and paginating the PrimeNG data table causes the webpage to automatically scroll to the top

Currently utilizing PrimeNG Datatable with pagination enabled. When attempting to sort a column or click on pagination buttons, the page automatically scrolls to the top. This behavior is due to the default href="#" in Primeng anchor tags. For example: & ...

Steps to implement the click functionality on the alert controller and modify the language in Ionic 4

I am currently developing a multilingual Ionic 4 app and have implemented the alert controller to display language options. However, I am facing an issue on how to dynamically change the language based on user selection. Below is my app.component.ts code ...

Tips for successfully passing an Observable identifier to mergeMap

Monitoring the outputs of a list of observables with mergeMap is straightforward, as shown in this example code snippet: export class TestClass { test() { const observableA = of(1, 2, 3); const observableB = of(7, 3, 6); const observableC = ...

How can I wrap text in Angular for better readability?

I've created a calendar in my code that displays events for each day. However, some event descriptions are too long and get cut off on the display. Even after attempting to use Word Wrap, I still can't see the full text of these events unless I c ...

Is there a way to access a component based on its route in Angular 7?

I am currently utilizing the NavigationEnd event to identify the current route after it has been changed in the following way: this.router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event) => { const na ...

What is the best way to retrieve a data type from an array using typescript?

Can Typescript automatically declare a type that retrieves the inner type of an array? For instance: Assume the following code snippet already exists: export interface Cache { events: Event[], users: User[] } type CacheType = Event[] | User[]; ...

Vue alert: Component resolution failed while attempting to create a global component

I am new to Vue Typescript and I have been encountering an issue while trying to create global components. I received a warning and the component did not load on the template. Here is how I attempted to create global components: App.vue import { createApp ...

Fastest method to invoke a potentially undefined function

With a background in C#, I am familiar with the null-conditional operator which allows you to call a function while avoiding a potential null-reference exception like this: Func<int> someFunc = null; int? someInteger = someFunc?.Invoke(); // someInte ...

The Angular material table is having compilation issues due to an unexpected closing tag for "ng-container"

Currently, I am in the process of working on an Angular project that involves integrating Angular Material version 5.2.5. Below is a snippet from my app.component.ts: import { Component } from '@angular/core'; import {MatTableDataSource} from & ...