Questions tagged [angular2-services]

This tag is designed for inquiries concerning Angular 2 Services, which are specialized JavaScript functions dedicated to carrying out specific tasks.

Show objects based on issuance date

I have implemented a function to retrieve a list of items from a feed URL as shown below: getFeed(){ return Observable.interval(5000) .mergeMap(() => this._http.get(this.feedUrl)) .map(this.extractFeeds) .catch(this.handleError ...

Error when sending Angular 4 GET request with multiple Headers results in a 400 bad request code

I've been attempting to perform a POST request with headers in order to receive a response. The Angular code snippet I'm currently using for this request is shown below: const headers = new HttpHeaders({ 'Content-Type': 'text/plain', 'Toke ...

tips for accessing the value outside of the subscription in angular2

Created a function within the component.ts file inside the constructor: constructor(private _visitService: VisitService,) { this._visitService.getchartData().subscribe(data => { this.fetchedData = data console.log("INSIDE SUBS ...

Utilize forRoot to pass configuration data

When using Angular, I encountered a challenge in passing configuration data to a custom library. Within the user's application, they are required to provide config data to my library through the forRoot method: // Importing the custom library import { Sa ...

Ways to eliminate duplicate objects from an array using Angular 6

I'm having trouble removing duplicate value objects in an array and it's not working as expected. I believe the duplicate function is functioning correctly, but the changes are not being reflected in the li list. Can you pinpoint where I need to ...

Performing a series of get requests in Angular 2

There is a configuration service that retrieves specific information from a JSON file. getConfiguration(key) { return this.http.get('./app/config/development.json').map(res => { this.result = res.json(); return this.result[key]; }) ...

Tips for retaining behavioral subject data during page reload

I'm currently working on a component called properties.component.html that displays real estate properties. Whenever a user clicks on a particular property, I update a Behavior Subject to reflect this selected property. private property = new BehaviorSubj ...

Subject fails to subscribe to the change

There are two components in my project that share a common service. shared.service.ts // ..... skipping top level codes private pickAnalysisForBubble = new Subject<any>(); analysisForBubble$ = this.pickAnalysisForBubble.asObservable(); mapTo ...

Issue with Angular2 not able to call POST method in CodeIgniter RESTful API resulting in 404 error

I am encountering an issue with my codeigniter restful API. While the GET method is working fine, I am unable to get the POST method to work from Angular2. this.api.post('quality/addeditquality', this.formdata).subscribe(data => { console.l ...

You can't access the values from one subscribe in Angular 2 within another subscribe (observable) block

Is there a way to properly handle the values from the subscribe method? I am facing an issue where I want to use this.internships in another subscribe method but it keeps returning undefined. Your assistance is greatly appreciated! Code: ngOnInit(): voi ...

The Ionic view is not reflecting updates in real-time when there are changes to the component properties

Having an issue with updating stock data on the view in my ionic 3 project. I am able to see frequent updates in my component and console, but these changes are not reflected on the view as frequently. For every 10 updates in the component, only 1 update i ...

Identify the locality and apply it to the root module of Angular 2 by utilizing a provider

I am working on a function that detects the current locale and I need to set it in the root App module of Angular 2 using a provider so that I can access it in all other components. I understand that I can achieve this by following the code below: { pr ...

You cannot access the property 'subscribe' on a void type in Angular 2

fetchNews(newsCategory : any){ this.storage.get("USER_INFO").then(result =>{ this.storage.get("sessionkey").then(tempSessionKey =>{ this.email = JSON.parse(result).email; this.newSessionKey = tempSessionKey; this.authKey =JSON.stringify("Basic ...

Keep an eye on the output of Firebase database in Angular 2

Just starting out in angular, so please be patient :) Using Angular 2 (version 1.0.4), Angular CLI, and NodeJs 7.9. I've been trying to create a centralized service that checks if a user is logged in, retrieves their data, and sends it back for the ...

Exploring the potential of Angular2's WebSocket service by efficiently accessing the parent component

I need some assistance with implementing WebSockets in my angular2 application. However, I've encountered a minor issue that I can't seem to solve. Here's what I have so far: I've created a service that has a method for creating a WebSocket object. This m ...

Ways of invoking a component method from a service in Angular 2

I have a concept for creating a unique service that is capable of interacting with one specific component. In my application, all other components should have the ability to call upon this service and then have it interact with the designated component in ...

Storing data in Angular 2 services for safekeeping

I have multiple sub-components that each receive specific data from a main component. These sub-components only receive the data necessary for display purposes. My goal now is to create a service that can make a request to a server. The problem is, this re ...

How to Retrieve Class Variables in Angular 2 Form Validator Function

I'm in the process of creating a modal-driven form with custom validation requirements. Specifically, I want to ensure that the user's password meets certain criteria (including having an uppercase letter, lowercase letter, and number). Instead of writing ...

Tips for managing the output of an asynchronous function in TypeScript

The casesService function deals with handling an HTTP request and response to return a single object. However, due to its asynchronous nature, it currently returns an empty object (this.caseBook). My goal is for it to only return the object once it has b ...

The Angular 2 component is experiencing difficulty in fetching data from the service

My current predicament is fairly straightforward - I am attempting to fetch data from an Angular 2 service, but the target array always ends up empty. Despite seeing that the API call returns data with a status of 200 and no errors are displayed in the con ...

Tips for preserving data upon page refresh in angular 2/4

As a newcomer to Angular2/4, I am facing an issue where the details fetched and saved in my interface are disappearing upon interface refresh. How can this problem be resolved without losing the interface details after a refresh? Here is my Login.componen ...

The Exception: Angular Two ExpressionChangedAfterItHasBeenCheckedError

I have thoroughly reviewed the documentation regarding this error and I believe I comprehend the underlying cause. However, I am currently struggling to find an alternative architecture that would be suitable for my needs. Within the root component of my ...

Encountering a problem in Angular 2 when trying to pass undefined variables between components while fetching data from

My approach involves making a single API call and storing the response in a global variable within my Service. I then utilize two helper functions to share and manipulate this value between parent and child components. repairs.service.ts public myItems:a ...

Encountering a "subscribe is not a function" error while attempting to utilize a JSON file in Angular 2

My attempt to import a JSON file into my service is resulting in the following error: Error: Uncaught (in promise): TypeError: this._qs.getBasicInfo(...).subscribe is not a function(…) The current state of my service file is as follows @Injectable() ...

Top method for dynamically generating a recursive treeview from data fetched from an API

I am currently learning Angular 2 and working on creating an expandable tree-view that pulls data from a potentially large third-party API. The underlying structure of the API is structured like this: - Home (id: 1053) - - Rugby League (id: 1054) - - - Su ...

Loading the value of a Subject variable in an Angular 2 application using Typescript

I am currently developing an Angular2 application where I am loading data from a service into my component as a subject. public type1Choisi: any; constructor( public formeService: FormeService, ...) { this.formeService._type1.subscribe(type1 => ...

Exploring the sharing of observables/subjects in Angular 2

UPDATE: After further investigation, it appears that the SharedService is being initialized twice. It seems like I may be working with separate instances, causing the .subscribe() method to only apply to the initiator. I'm not sure how to resolve this issu ...

"The response from an http.post request in Angular 2 is displaying

I'm struggling with a problem that seems impossible to solve. I understand Make no assumptions about the server API. Not all servers return an object with a data property. but I have no clue on how to handle it. How can I send data to: dat ...

Ways to utilize and display data in a *ngFor loop

I have created a simple service for accessing an HTTP service. Can anyone help me with how to bind this service information in *ngFor? import { Component } from '@angular/core'; import {Http } from '@angular/http'; import { Injectable } from '@an ...

Exploring the Implementation of Date/Time Service in Angular 2

My current project involves setting up a simple service in Angular 2. The objective is to have the current date and time displayed when a user clicks a button. However, upon implementing the code provided below, I encountered an error: Error during evalua ...

Typescript encounters issues when assigning declaration as TRUE

Currently, I'm working on a project in Angular 2 and attempting to create TypeScript definitions for it so that it can be exported as a library. I have various services set up that make HTTP requests to components, all structured similarly to the cod ...

Error: Unable to locate Angular2 Custom Service

I have implemented a custom service to populate a list of people in my HTML. Below is the code for my custom service: app.peopleListService.ts import { Injectable } from '@angular/core'; import { Person } from "../model/peopleModel"; @Injectable() expo ...

Dealing with race conditions in Angular 2 nested resolvers and managing them effectively using RX

Back with an intriguing predicament! Currently, I am in the process of developing an angular2 application using RXjs observable data stores to supply data to my app. Upon launch, if a user is logged in, the app resolvers fetch the relevant user data and po ...

Stop /Terminate the Angular 2 HTTP API request

Occasionally, the loading time for an http API call can be quite lengthy. However, even if we navigate to another component, the call still continues execution (which is visible in the browser console). Is there a method or approach that allows us to can ...

Retrieve error information from ResponseContentType.Blob request type

I am currently struggling with an issue related to making a request of type ResponseContentType.Blob and receiving an error message when the call fails. The code I am using is quite simple: let headers = new Headers({'Content-Type': 'application/json'}) ...

The local scope in Angular is inaccessible within an observable subscription

I've been grappling with this issue for quite some time and have experimented with numerous solutions. It seems that within my subscribe function, I'm unable to access ChangeDetectorRef or NgZone in order to trigger an update on the scope. Why is nothing ...

Tips for incorporating recursive HTTP requests into an Angular2 service to efficiently retrieve data in advance

In my Angular project, I am using a service to fetch data from an external API. However, the API has a limit of 100 records per request and I can only determine the total number of records available after fetching the first batch. The response structure o ...

"Receiving HTML response from an HTTP GET request in Angular 2

Attempting to transmit test data from my node.js server to the front end. router.get('/abc', (req, res) => { return res.json({ test: "success!" }); }); In my service component: private url = "http://localhost:4200/auth/abc"; getTitles() { ...

Having issues with Angular 2/4 unable to read an object within the initForm() function

In the process of creating an edit form using Angular, I am facing a problem with understanding the lifecycle of the object retrieved from my backend server. After making a call to my service in ngOnInit(), I receive valid data. However, when I assign this ...

Sending information from the AppComponent to another component that is loaded at a separate time

Is there a way for me to maximize efficiency when fetching data from a service in the AppComponent and then passing it on to another component that's loaded later? I'd like to minimize API calls by reusing the same data in multiple places. How can I make ...