Questions tagged [angular-services]
Angular services are substitutable objects that are wired together using dependency injection.
2,059
questions
1
vote
0
answers
34
views
Angular 17 not rendering a component with Socket.io
I have the following Angular component, whose only property is an instance of ConnectionService service:
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
...
1
vote
1
answer
48
views
I got a problem with a service in Angular 16
I'm working with Angular 16 for a project that involves using balkan family tree , but I got stuck with a problem in a service
This is the function where it emits the value, is using HttpClient from ...
0
votes
2
answers
69
views
Can a resolver use the same service instance form another module except the AppModule in Angular?
I have a lazy loaded module with all it components declared and routes added in RouterModule.forChild()
but some of these routes have their resolver that will prefetch some data And call a service to ...
0
votes
1
answer
50
views
Share service instance between multiple components
Suppose you have 3 lazily loaded components, A, B, and C – this means they are not loaded eagerly, as soon as possible, but depending on some condition (e.g., a back-end response).
Is it possible to ...
2
votes
2
answers
84
views
Angular service data caching with RxJS
I have an angular service that is specific to a type of data in my project. Right now it just passes everything straight trhough to a generic data service that handles the HTTP requests.
@Injectable({
...
0
votes
2
answers
63
views
Where to provide angular services for storing data
I want to use ngrx component-store/service with a subject in my application, however I am in a situation where I am not sure whats best. I hope you can guide me in the right direction. (The following ...
0
votes
0
answers
41
views
'ng generate service' command says 'Nothing to be done'
I want to create a service service file. But when I am giving
ng generate service my-service it returns 'Nothing to be done'.
There doesn't exist a file with the same name in my project folder.
...
0
votes
0
answers
26
views
Angular service call to .Net api controller not working
I have one angular solution where service method calls api controller. but it is giving error. Code is given below :
user.service.ts
getMonthlyData(date: string): Observable<UserProfile> {
const ...
0
votes
0
answers
42
views
How to load paypal button component button twice from two different parent component in angular
am using PayPal component to load PayPal button in shared component so trying to access from two parent components, but unfortunately it shows the button in first component. If i tried with set ...
0
votes
1
answer
42
views
How to wait for the information to be received by the service and then use it in angular
I wrote a service that receives permissions data from the API, and based on these permissions, I show or hide parts of the menu. But I want it to show or hide parts of the menu only after receiving ...
0
votes
1
answer
26
views
Scrolling to a component on click
Let's say I have a landing page with a button, and I want that when I click on that button I get redirected to another page that has multiple components (imagine a page with a lot of small blocks, ...
0
votes
1
answer
127
views
Angular loading mat-spinner not firing
I am wondering why my loading spinner is not firing, and I think it may be due to my confusion in regard to my LoadingService at the app level, and my LoadingService as a provider at the page level.
...
0
votes
1
answer
35
views
My service call function is giving response when called in another function
I am trying to call a function which is indeed a service call (a http request), I want to use that response for the lines below the function call. as the response is depended upon it.
And this code ...
1
vote
1
answer
33
views
Pass a value to another component using Services when a change in value (dropdown selection) happens in the parent component - Angular
I'm trying to pass a value (year_value) from a parent component to a child component using services, whenever there is a change in the value (dropdown selection). Also I'm using Angular routing (<...
3
votes
1
answer
44
views
Chart disappears, but it shows when I press f12 (?)
I use chart.js and I load data with service from db.
After reloading it's not shown, but when I press f12 to open the console it appears like nothing happened.
component ts:
import { Component } from '...
0
votes
1
answer
41
views
Why an attribute of an Angular component is automatically updated by a timer instantiated in a service?
In my Angular project I have defined:
a service myService
a component MainComponent
The service myService
The service contains a timer that updates, when started, the attribute currentTime. The ...
1
vote
2
answers
277
views
Value of BehaviorSubject in Service (to share data between component) is not updated
I'm trying to use a service with BehaviorSubject to share data between my root component and a component.
Here is the service :
@Injectable({
providedIn: 'root'
})
export class UserService {
...
0
votes
1
answer
31
views
Share logged user object with service but data is lost between component
I have created an injectable UserService class to store an object (the logged user).
@Injectable({
providedIn: 'root'
})
export class UserService {
private _loggedUser : User;
setLoggedUser(...
0
votes
2
answers
135
views
Using set of data provided by Service and Interface in Angular to view only selected data in Component
I have created Interface and Service for my test data:
interface.ts
export interface IColumn {
label: string;
value: string;
}
export interface IRecords {
Lp: string;
id: string;
pluginName:...
0
votes
0
answers
20
views
Allowing only specific components to manipulate observables in services that are shared across multiple components in Angular
I've created a service with a private Subject<T> and a public Observable<T> that corresponds with it, and I'd like to inject the service into multiple components so that they can access ...
1
vote
3
answers
457
views
How to use an Angular service inside an RXJS Custom Operator?
How do I use an Angular service in my custom rxjs operator?
Is it possible to do this?
function myOperator() {
return function <T>(source: Observable<T>): Observable<T> {
...
0
votes
0
answers
48
views
Conditional component rendering on newest value from subscription angular
I have a parent and a child component in Angular. The parent component has a property of array which is set as a subscription and updates when a change takes place. Like this:
export class ...
0
votes
1
answer
880
views
How do I provide single instance of service for component and all content children?
Is there a way I can provide my component-scoped service to all of its content children?
For context, I am building out a table component that contains multiple components and directives that are ...
8
votes
1
answer
5k
views
NullInjectorError - Root standalone component does not import HttpClientModule properly
I have an issue, I want to rewrite my app code and change main module to main root standalone component pointed in main.ts.
All works fine but I have an issue with HttpClientModule. I am using ...
0
votes
2
answers
218
views
How to pass data through service if change detection method exist in one of the component?
I need to update the color of particular box in one component by getting input from second component. For this I am using service to pass data but due to change detection i can't update color. I need ...
0
votes
0
answers
43
views
Data communication between Interceptor and component to handle global error handling banner
I have below scenario, each component have different type of API post call on tab change.
Component A, Tab A
first name AA
Component B, Tab B
first name BB
Added global error handling component ...
0
votes
2
answers
71
views
Should get and Post requests be in separate angular services [closed]
I am wondering if separating angular services for post request and get request is a good angular coding practice ?
Basically the question is the following, you have an api that returns a list of ...
3
votes
0
answers
369
views
With providedIn: 'any' and providedIn: NgModule now deprecated are there any other options other than root?
Across Angular v14 and v15 releases, the providedIn: 'any' and ProvidedIn: NgModule are now deprecated. Is 'root' now the only valid value for providedIn? I realize that you still have the option of ...
1
vote
1
answer
140
views
Angular service not working when injected in to HttpInterceptor
I'm trying to create a HttpInterceptor to catch any errors in http responses. My HttpInterceptor catch errors as expected. But when i use "ngx-toastr" to display error message using a ...
0
votes
1
answer
158
views
How to update Array value in Service using Input from child component?
I am trying to update the value of an Array in my service from child component.
Here is the service at the top level of application
feature.service.ts
export class FeatureService {
private ...
0
votes
1
answer
89
views
Angular subscribing to a service BehabiourSubject inside the service
I'm trying to subscribe to currentTheme BehaviorSubject inside the service itself
@Injectable({providedIn: 'root'})
export class ThemeService {
currentTheme: BehaviorSubject<string>;
...
0
votes
2
answers
55
views
Form Validation from service.ts Angular
I need to add custom validators to a form from formvalidation.service.ts
form.component.ts
myForm = this.formBuilder.group({
name: ['', [Validators.required,]]
});
formvalidator.service.ts
...
0
votes
2
answers
650
views
ANGULAR - Pass variable from Component to Service
I've been looking at component interactions and passing values from one component to a service, but couldn't find something clear enough.
The premise is simple, I have a variable / value that's coming ...
1
vote
0
answers
55
views
Aliasing a service lazy loaded from a module
If I define a Route in my AppModule to alias a provider that is included in the module, like so:
{
path: "my-path",
loadComponent: () => import('./my-component'),
providers: [
{
...
-2
votes
1
answer
75
views
Data is not displaying on template (Angular)
I am practicing Angular by doing simple project. I see all Q&A on SO which is quite similar with my problem. Reason is that I am trying to display the async data before it initialized into ...
0
votes
1
answer
495
views
Dynamic Header for angular app based on user type
So I am creating a SPA on angular and i have to change the header based on the user. I created an archiecture component which has the header and footer and i have set it to the app component with the ...
0
votes
0
answers
84
views
how to load data from nested service in ag grid angular
In my HTML code I have 2 tabs which run getData() for selectedTabChange Event. In tab 1, I have a ag grid which gets data from service through getData(). In getData() function, I call 2 nested service,...
1
vote
1
answer
4k
views
NullInjectorError: No provider for service in library
Problem:
I work in angular workspace and I import common.module.ts from library (library generated with ng generate library) to my app.module.ts, but when I inject CommonService in app.component.ts I ...
0
votes
0
answers
75
views
Angular 14 : I have service in a module and I want to use it in other module but VS code says that could not find it
Cannot find module '../../myservice;' or its corresponding type declarations.
By having the service as Injectable with providedIn root , this should be available throughout the project right?
@...
0
votes
0
answers
320
views
ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[TestComponent -> TestService]:
I am learning how to share a variable between two components with a service.
Component A (Service):
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
...
0
votes
0
answers
266
views
In Angular 14, how do I find the value of"publicHost" (from angular.json) within my service?
I'm using Angular 14. In my angular.json file I have
"serve": {
"builder": "ngx-build-plus:dev-server",
"configurations": {
"...
0
votes
3
answers
492
views
Angular doesn't write the value after updating sessionStorage
My code is pretty simple, I have this html in my component
<h2>{{username}}</h2>
<h2>{{sessionId}}</h2>
An this is the script I use to update those variables
//i check ...
-2
votes
1
answer
183
views
How to store a set variable in service.ts then use it where I call it?
Guys I've got a problem with this:
I have variable
userdata?: any
In my service.ts then I set it in some other component .it works and when I console.log IT /in service.ts/ ,it works. But when I call ...
0
votes
0
answers
55
views
How do I use ".then function" after I Customized my UIKit Modal while using in Angular Service
So I customized my code as per my need and now i couldn't use "then(function(){}" like before ,So below is the code i wrote to customize UIKit Modal
So Is there anyway i could customize ...
1
vote
0
answers
29
views
optional parameter in Angular service
I have this service in my Angular Project
getActividades(usuarioId: number, año: number, mes: number, quincena?: number): Observable<IActividad[]> {
return this.http.get<IActividad[]>(`${...
0
votes
1
answer
1k
views
Angular 15: call a function every time a value changes
our professor asks us to build a simple e-commerce app with the following components: customers, orders, menu (a navbar) and a cart. We need to display the orders in the front-end depending on the ...
0
votes
1
answer
352
views
Injecting service in the class / pure functions
I am working on Angular project (Angular 14+) and following atomic design principles (creating minute level components like button, input, toggle etc.).
Most of the views (list, forms, headers) are ...
1
vote
2
answers
125
views
Type 'undefined' cannot be used as an index type. Partial<Class> undefined?
I searched a lot but couldn't find. My Codes as below.
I created one alertify Service but I get the following error: "Type 'undefined' cannot be used as an index type. Partial<Class> ...
2
votes
1
answer
129
views
AngularJS ng-if is not working while the condition is true
I'm using angular.min.js 1.8.2 for Coursera AngularJS Single Page Application.
I created an itemAdder to add a shopping list by users, the items will show in showList. Once you bought the items, you ...
0
votes
0
answers
94
views
In Angular, how can I wait a function finish before execute a post petition that returns an observable?
I need to generate a Google reCAPTCHA V3 token and send it on the body of my post petition. Something like this:
let body = {}
@Injectable({
providedIn: 'root'
})
export class SujetoObligadoService ...