Questions tagged [angular2-services]
Use this tag for questions related to Angular 2 Services, which are JavaScript functions responsible for performing a single task.
2,203
questions
1
vote
1
answer
33
views
access the properties of an object inside an object class which is also inside an object class
How do we access the properties of an object inside an object class which is also inside an object class?
Here I can access test.company.phone but not the test.company.company_name.company_id in the ...
0
votes
0
answers
32
views
$scope.$on replacement in Angular 2+
in my component which I am migrating Angular js to angular 2+, I have $scope.$on which is getting data broadcasted from controller which is in Angular js. is there any replacement for $scope.$on(){} ...
1
vote
0
answers
115
views
Angular Firebase Authentication issue - custom userModel
I'm still quite new to Angular, and the project that I'm currently working on is using Firebase for database, hosting, and authorization purposes.
I have been following some tutorials from the web and ...
0
votes
0
answers
49
views
Pass data from one app to another app in angular 2
I have embedded app2 inside app1 using an iframe. Now I want to pass data from app1 and show it in app2. How can I do it?
0
votes
1
answer
53
views
How to write a function where I can pass the key of the enum as a string and get the value mapped to it? Using angular 11
The code in my service.ts file is :-
import {injectable} from '@angular/core';
export class ConstantService{
constructor(){}
public enumTemp = {
one:'this is one',
two:'this is two',
three:'this ...
0
votes
1
answer
250
views
Angular 2+ Http post request responseType blob does not show json errors returned by server
I have a backend method that return a file (blob). For that I am setting the responseType of angular http post call to blob. Everything works just perfect and file is downloaded successfully.
However ...
-1
votes
1
answer
152
views
(Angular 12) Search button response data is not show in template before Click the button twice
Here is my search input box and button
<div class="col-lg-8">
<input #text class="form-control" placeholder="Search Customer" required/>
</div>
...
0
votes
0
answers
87
views
Angular 12 Web Component can't access method inside of service
I am creating a web component that will be used inside of external websites and for some reason, I'm not able to access the service method I am defining..it just comes back as undefined.
Module File:
@...
-3
votes
1
answer
35
views
Bundle together Services in Angular
I'm trying to find a nice way bundle together several services.
I have several services that communicate with my backend (which are provided by my backend team) and I want them to be accessible ...
0
votes
0
answers
58
views
How to use Runtime Configurations in Angular Modules
I am trying to implement "Build once Run Everywhere" in my angular app.
As many of the blogs and suggestions I read, I have created a config.json file under assets folder. Created a service ...
0
votes
0
answers
27
views
How angular 11 application trusts server CA certificate
How angular 11 application trusts server CA certificate
Having Angular 11 application that uses HttClient library to call to REST APIs, now need the ways to trust server(REST API) CA certificate.
0
votes
2
answers
45
views
how to display uesrname after the user logged in without filling the user details on login [closed]
I would like to display my user fullname on profile page.
I know I need to set the user somehow, but I do not know how.
I do not have the user fullname from login input, I got it in the server.
I do ...
0
votes
1
answer
43
views
Cannot read property 'subscribe' of undefined karma jasmine
I need to create a test of this get, but every time I try I get the error "TypeError: Cannot read property 'subscribe' of undefined"
My service function
getAPICard(): Observable<any> {
...
0
votes
1
answer
28
views
Simplify access to service data on Angular2 components
On my Angular2 projects i used to create a service to care about the system authentication, and on this service i store the user data on an observable.
I want to avoid to repeatedly create a local ...
1
vote
1
answer
173
views
How to GET API data from server in Angular App?
I have problem with write data in component. I write objects data in console but i don't know how to data get to component from objects.
This data I GET from server to console:
IMAGE. I need extract ...
1
vote
0
answers
66
views
Error on res ['casesbyState'] and can't resolve
With the following code:
let name = res['casesByState'].map(res => res.name)
let casesReported = res['casesByState'].map(res =>res.casesReported)
this.chart = new Chart(this....
0
votes
0
answers
161
views
update *ngFor with ChangeDetectorRef
I've got a little problem and one of these days where I can't seem to find a good solution for it. I tried some solutions from similar questions but without success.
When the user is logged out, all ...
-1
votes
2
answers
206
views
How to load http data first before the execution of any function in the component/service in Angular?
Hope you're doing well in this difficult time. Trust all is well in your end.
I am trying to make a local JSON call but after compiling the code, the json response which I am receiving is, is at the ...
0
votes
1
answer
895
views
"jwt_decode__WEBPACK_IMPORTED_MODULE_11__ is not a function" Error in ionic/angular/capacitor while trying to decode token with jwt-decode npm package
I have utilized jwt-decode package to decode the received token.
import * as jwt_decode from "jwt-decode";
and on receiving a valid token, let's call it variable tok.
On decoding the token
...
1
vote
0
answers
32
views
Angular 7 Service returns undefined when has metadata dependency
When I use inject metadata to working service, it starts to return undefined.
import {BasePolicy} from '../base.policy';
import {Inject, Injectable} from '@angular/core';
import {AUTH_USER_TYPE} from '...
1
vote
0
answers
54
views
How to send server error request when ever error happen in Angular application?
I have a global error Interceptor which handles the error when server return error response. I have error interceptor to handle that.
In my use case whenever an error occurs in angular app , consider ...
0
votes
1
answer
107
views
Base service undefined when trying to handle an error, Angular
I have a service that extends a base service for to handle error data.
For example
import { CurrentUserService } from './current-user.service';
import { CONFIG } from './../shared/base-urls';
import ...
0
votes
1
answer
312
views
How to execute a subscription ngOnInit only one time in a nested component
I have two components: CreateComment and DisplayComment. DisplayComment component has itself nested in it for displaying the threaded comments.
Now, whenever I create a comment from CreateComment ...
1
vote
0
answers
735
views
How to save each edited row data of a table in Angular (version 2 onwards)
How to save each edited row data of a table in Angular (version 2 onwards), I am getting edited values as blank. Can Anyone provide me a sample html with ts file for edit and save each row data in ...
1
vote
1
answer
536
views
API call is not hitting the controller from Angular 2 UI
While calling the URL from angular 2 through http.get() it is going to exception and not hitting the debugger in the controller. I changed the proxy, checked the routing but those are same for my ...
3
votes
3
answers
376
views
Angular 2 prod build error : ERROR in Error: Illegal state: Could not load the summary for directive
I'm using angular 2 for my project, when I use ng build and ng serve I'm not getting the following error. This is only happening when using prod build ng build --prod
ERROR in Error: Illegal state:
...
0
votes
1
answer
217
views
Behaviour Subject is loading data in console but template is coming blank in angular
I am working on an angular app where I am subscribing data in service and emitting data using Subject in component.html and in component.ts I am subscribing to get the latest value.
My problem is ...
0
votes
2
answers
133
views
Fetch Data from two http get request from firebase and combine them in single array in angular and display it on page
I am working on angular app where I want to display my post which are coming from two different collection
i.e is Public and private. Now I am making two http request and I am getting data but I am ...
-2
votes
1
answer
107
views
Angular is it a good practice [closed]
I'm making a medium size application and I wonder about the my practice with data binding.
Im passing the data directly from the service to template in this way:
<ion-list class="list-...
0
votes
1
answer
135
views
How can i use the environment variable in gulpfile.js file Angular 8?
I have gulp file in root directory but the environment files are under
src/environment. How can i externalize the environment variables so
i can used variable values in root directory file!
-1
votes
2
answers
304
views
Angular8: route to 404 if no data returned, BEFORE component shows
Using Angular8, I would show the a user's profile by the url's params-id:
http://localhost:4200/user/El231A
If no user can be retrieved, I would route to my 404 error page.
Now the below code works ...
0
votes
1
answer
26
views
Datatable - Can´t call service inside custom action
In Angular i have a Datatable. This datatable has a custom button and action, like this.
buttons: {
buttons: [
{
action: function(e, dt, node, config) {
this....
0
votes
0
answers
54
views
How to make component A display data at component B in Angular 2
How do I go about writing logic in component A to accept input data from the user, and make those data display in a table found in component B?
1
vote
0
answers
1k
views
Angular 8 return HTML from rendered component
I want to dynamically generate a component to extract it's HTML, return it from a function and pass it as [innerHTML] to maintain page-texts with HTML-content.
To achieve that I wrote a service to ...
2
votes
2
answers
2k
views
appsettings.json file loading after app init on APP_INITIALIZER
I've been trying to deploy on DevOps an Angular 8 application and use configuration inside .json files in order to not re-build the entire application for different environments.
I used these 2 posts ...
1
vote
1
answer
5k
views
How to fetch the <p> tag dynamic value and pass it into typescript using angular 2
I have the below html tag in app.component.html
<p id="demo">dynamicValuegoeshere!!!</p>
The above paragraph is having some dynamic value which is inserted by javascript. But currently ...
0
votes
1
answer
599
views
X509 Certificate does not display expiration date correctly. Is there a special format for the timestamp?
I'm having an issue where X509 certificate expiration timestamp logged from the console does not match it's actual timestamp from KeyStore explorer.
It is not formatting correctly with the Angular2+ ...
1
vote
0
answers
90
views
is it possible to convert protobuf data to json in angular 2 version
Need to convert row protobuf data into JSON object like mentioned in image using angular 2 only.
I have content type for service call header is
'Content-Type': 'application/protobuf'
Need to ...
0
votes
0
answers
77
views
Provide non-singleton service in module
Is it possible to provide a service in a module so that it creates a new instance whenever it is injected?
I know I can provide it in a component's decorator and it will create new instances, but I ...
0
votes
1
answer
505
views
Angular 8 testing Routing on a Service
I am testing an Http Interception service that uses routing to navigate to another url when it returns an error response, all my tests currently pass as I am not testing the routing itself, however an ...
1
vote
1
answer
563
views
How to manage API function call services in Angular 7
I finished an Angular 7 web app (Roughly). As an example, I have a documents.service.ts file and it includes below HTTP GET request function:
public sendOnlyCoverPage(strProNo: string, ...
0
votes
1
answer
649
views
Property 'projectNodes' does not exist on type 'Renderer2'
I am migrating my Angular project from Angular 4 to Angular 8. Currently I am updating Renderer to Renderer2. I have a code snippet
this._renderer.projectNodes(document.body, [this._element....
1
vote
1
answer
205
views
How to load component as content in jsPanel Angular2
I am trying to load an Angular component in jsPanel, but it doesn't work yet. Chrome DevTools always show <app-chat-tab></app-chat-tab> instead of the component html, so I think it's not ...
1
vote
1
answer
49
views
Is a not injectable service still a service or is it better to use something different?
I found so many different answers to this problem and I'm always looking for best practices.
I have created a service of which I need multiple instances. This services takes some data as an input and ...
0
votes
1
answer
62
views
Find a Specific Element of an Observable Array and Display in Component HTML
In an Angular 8 accounting application, I have a service for journal entry batches that gets all of the batches and saves to a BehaviorSubject and also a readonly observable of that behaviorsubject. ...
0
votes
1
answer
231
views
Invoke modal inside SwitchMap in angular2 resolver
I have a requirement of displaying modal popup based on warning message inside angular resolver. I am making a service call to API and using combineLatest and SwitchMap returning multiple responses. I ...
0
votes
1
answer
189
views
How to subscribe to error case in angular service unit testing
I am trying to subscribe to the response and as well the error case but when I see the coverage its not going to err case.
I have the following fake service,
My service,
fakeService: {
...
2
votes
2
answers
5k
views
How to call a component method from service class - Angular
I am trying to call component method from service class, but I am getting an error like 'ERROR TypeError: Cannot read property 'test' of undefined'. But I went through similar kind of issues but there ...
2
votes
2
answers
9k
views
Subscribe to Observable vs subscribe to Subject
There are different methods to get data from server in Angular application:
Get Observable from the service and subscribe to it at component
Create Subject at the service and subscribe to the Subject ...
0
votes
1
answer
56
views
How to unsubcribe a timer service call using takeUntil
I am calling a service regularly after a certain interval of time. I get two numbers as result in the service response,I want to compare those numbers and if they are equal I want to end the service ...