The values obtained from an HTTP GET request can vary between using Curl and Ionic2/Angular2

When I make a GET request using curl in the following manner:

curl https://api.backand.com:443/1/objects/todos?AnonymousToken=my-token

I receive the correct data as shown below:

{"totalRows":2,"data":[{"__metadata":{"id":"1","fields":{"id":{"type":"int","unique":true},"content":{"type":"string"}},"descriptives":{},"dates":{}},"id":1,"content":"the first todo!"},{"__metphilipphpphilipphilip"}]}

However, when I attempt the same request in Angular 2 like so:

this.http.get('https://api.backand.com:443/1/objects/todos?AnonymousToken=my-token').map(res => {
  return res.json();
});

I am receiving an unexpected object called observable that appears strange like this:

https://i.sstatic.net/08Pce.png

What could be causing the issue with the Angular request?

Answer №1

Although I have limited knowledge about Curl, when it comes to HTTP calls in Angular 2, they return observables. This means you must utilize RxJS methods to work with the data. To retrieve the response, you will need to subscribe to it so that you can observe the values that are being returned.

 this.http.get('https://api.backand.com:443/1/objects/todos?AnonymousToken=my-token')
    .map(res => res.json())
    .subscribe(
      data => this.myData = data,
      err => this.logError(err),
      () => console.log('Request Complete')
    );

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

Error message in my Angular project: Invalid Target Error

Out of nowhere, I encountered an invalid target error while running my Angular project with the command: npm start An unhandled exception occurred: Invalid target: {"project":"agmbs","target":"build","configur ...

bind a class property dynamically in real-time

I need to dynamically generate a TypeScript class and then add a property to it on the go. The property could be of any type like a function, Promise, etc., and should use this with the intention that it refers to the class itself. let MyClass = class{ ...

What is the best way to locate the Sass file corresponding to a specific HTML page in Ionic?

According to the Ionic guide at Ionic Framework Tutorial The instructions suggest adding the styles in the Sass file for the respective page. I'm having trouble locating the Sass file for the HTML pages within the template folder. ...

Leverage the retrieved configuration within the forRoot function

Currently working on an Angular app that uses @ngx-translate. In my implementation, I am using TranslateModule.forRoot(...) to set up a TranslateLoader: @NgModule({ imports: [ TranslateModule.forRoot({ loader: { provide: TranslateLoade ...

Steps for automatically closing a TextPrompt if the end user does not respond within a specific time frame

How can I programmatically close a Prompt in Microsoft Chatbot SDK v4, such as TextPrompt or ConfirmPrompt, and end the dialog after a certain period of time if the user does not reply? I attempted to use setTimeout and step.endDialog but encountered issu ...

Unit test does not show the PrimeNG menubar start directive

Currently, I am in the process of writing Jasmine tests for my component which includes PrimeNG's menubar. Within this component, I am utilizing the start template directive in the following manner: <p-menubar id='menubar' [model]='i ...

There seems to be a syntax error in the regular expression used in Angular TypeScript

I've encountered an error and I'm struggling to identify the syntax issue. core.mjs:6495 ERROR SyntaxError: Invalid regular expression: /https://graph.microsoft.com/v1.0/communications/callRecords/getPstnCalls(fromDateTime=2020-01-30,toDateTime ...

Utilizing Higher Order Components with TypeScript in React Applications

My React component is typed with a generic, and I've extended it with a higher order component (redux-form). Below is a simplified version of my class and the HOC being applied: import * as React from "react"; interface MyFormProps<D> { pr ...

Using the $state feature in TypeScript with Svelte 5 for defining class fields

Currently, I have a class implementation as follows: class TestClass { prop = $state('test'); } This code works smoothly in files with the extension .svelte.js, and .svelte using <script lang="js">, but encounters issues in f ...

What are the solutions for handling undefined data within the scope of Typescript?

I am encountering an issue with my ngOnInit() method. The method fills a data list at the beginning and contains two different logic branches depending on whether there is a query param present (navigating back to the page) or it's the first opening o ...

What is the reason behind TypeScript requiring me to initialize a property even though I am retrieving its value from a local reference?

I am just beginning to explore Angular. This is the template for my custom component: <div class="row"> <div class="col-xs-12"> <form action=""> <div class="ro"> <d ...

Encountering a MODULE_NOT_FOUND error while trying to execute "npm run build"

I have encountered an issue while trying to deploy my application on my GoDaddy server. Upon running 'npm run build,' I am receiving the following error message: PS C:\Users\trump\Documents\Rider Project\PreChiS-E---Stud ...

Configuration options for Path Aliases in TypeScript

In my Next.js project, I am utilizing TypeScript and have organized my files as follows: |-- tsconfig.json |-- components/ |---- Footer/ |------ Footer.tsx |------ Footer.module.sass My path aliases are defined as:     "paths": {       ...

Storing a child in an existing object with Firebase and Angular 6

How can I save a new form to an existing list with the following code snippet: createNewTumeur(newTumeur: Tumeur) { this.tumeurs.push(newTumeur); const id: string = this.route.snapshot.params['id']; firebase. ...

Tips on creating type definitions for CSS modules in Parcel?

As someone who is brand new to Parcel, I have a question that may seem naive. In my project, I am using typescript, react, less, and parcel. I am encountering an error with typescript stating 'Cannot find module 'xxx' or its corresponding t ...

Error in TypeScript React component due to prop-types ESLint in React

I'm in the process of setting up a typescript-react-eslint project and I've encountered an eslint error with this boilerplate component: import * as React from "react"; interface ButtonProps { children?: React.ReactNode, onClick?: (e: any) ...

What is the best way to access an HtmlElement from an Angular component when outside of the

I've been researching extensively, but all the solutions I've found involve retrieving HTMLElement within the component itself or in other components. I am looking to retrieve HTMLElement from an Angular Component within a helper function or so ...

Creating a channel for communication between sibling components in Angular 4 by storing component references in a shared service

I am searching for a way to establish communication between two sibling Angular 4 components. After reviewing the documentation at https://angular.io/guide/component-interaction, my idea revolves around utilizing a service that stores a reference to the c ...

The data type 'number' cannot be assigned to type '(...items: any[]) => number'

Currently enrolled in an online Angular course with no prior programming knowledge. I am struggling to find the solution to my coding problem. What is the mistake and where should I look for it? Not using strict mode This is my HTML code: <button c ...

Encountering problems with TypeScript in a Node application when using the package manager

I am facing an issue while trying to package my node app into an exe using "pkg". I work with TypeScript, and when I attempt to run pkg index.ts --debug, an error pops up. Node.js v18.5.0 Warning Failed to make bytecode node18-x64 for file /snapshot/ ...