angular2-services

Don't know how to implement an enum using an interface in an angular2 class

不羁岁月 提交于 2019-12-04 03:50:15
Going around in circles here. Very new to Typescript and it's causing major headaches with trivial implementations. How do a define in AgentStatusService that it should have an array of 4 options called ['offline','available','busy','away'] ? AgentStatus is defined ( or is it? ) and I am injecting it into the AgentStatusService . Microsoft Visual Studio Code is barfing on line 21 where the type 'typeof AgentStatus' is not assignable to type 'AgentStatus'... why? Updated: import { EventEmitter, Injectable } from '@angular/core'; export enum AgentStatus { available =1 , busy = 2, away = 3,

Typescript errors when setting declaration to TRUE

淺唱寂寞╮ 提交于 2019-12-04 03:28:34
问题 I'm trying to create typescript definitions for a Angular 2 project I'm working on so that it can be an exportable library. I have several services setup that return http requests to components all quite similar to the following: public create(user:User) { return this.http.post(this._apiUrls.create, JSON.stringify(user), { headers: this.apiConfig.getApiHeaders() }); } Which I then call from a component something like this: Session.create(user).subscribe((res:Response) => { this.user = res

Dynamically load different css files in angular2 application based on user's language

折月煮酒 提交于 2019-12-04 01:03:22
问题 I have an Angular2 application and it need to support multiple languages. Some of these languages may be RTL (i.e Persian) and some will be LTR (i.e. English). Apart from localizing strings, I need to style my components based on the direction of the language. Now using this helper, I can have two separate files (i.e. app-rtl.scss & app-ltr.scss) which both import a single scss file (i.e. app.scss) which allows me to write my scss code in one place and automatically output two files; one for

Angular2: which is the best way to make multiple sync calls with Observables?

谁说我不能喝 提交于 2019-12-03 19:15:08
问题 I'm studying the Observables in Angular2/4, before I've used the Promises for my services call. I'm wondering what is the best way to make multiple sync calls. Let me explain with an example: my app component have a getUserInfo() method that need to make 3 calls to 3 different services that depends on each other. getUserId():Number // return the logged in user userId from the session getUserPermissions(userId):Array<String> // return a list of permission from the userId getUserInfo(userId)

Angular 2 service constructor with parameter

那年仲夏 提交于 2019-12-03 17:06:15
I want to initialize a service with argument. Each component will have its own service instance. @Injectable() export class LoggingService { constructor( @Inject('group') @Optional() public group?: string) { this.group = group; } } It can be injected in to the component like this : @Component({ selector: 'test', templateUrl: 'test.component.html', providers: [ LoggingService, { provide: 'group', useValue: 'Anythings goes here' } ] }) export class TestComponent implements OnInit { constructor(private logger : LoggingService) { } } Above functionality is working fine for me. I also want to

angularfire2 best way to increment a value?

喜欢而已 提交于 2019-12-03 16:29:07
I searched in many forums, questions, in doc but can't find the correct solution. Problem What is the best way to increment a value using angularfire2 ? I saw we could use [transaction()][] but it's not for angularfire2 actually. Or with snapshot ? user.service.ts incrementLike(userToIncrementLike){ this.af.database.object('users/' + userToIncrementLike.uid).subscribe((userObject) => { var newUser = { likes: userObject.likes + 1 }; }); this.af.database.object('users/' + userToIncrementLike.uid).update(newUser); } I tried also in this way : incrementLike(userToIncrementLike){ let obs = this.af

Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'

半腔热情 提交于 2019-12-03 15:52:22
Im Getting following error while trying to pass header in HTTP.POST/GET request Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'. Property 'null' is missing in the type '{header:Header;}' I have try many solutions but no lock on it. here my code : import { Injectable } from '@angular/core'; import { Response, RequestOptions, Headers, Http, URLSearchParams} from '@angular/http'; import { Observable, Subject } from 'rxjs/Rx'; import {Company} from './companyMaster'; import 'rxjs/add/operator/map'; import "rxjs/Rx"; import 'rxjs/add/operator

How to change NgModule configuration at runtime

北慕城南 提交于 2019-12-03 15:32:32
There are some modules that expose their service configuration, for example: AngularFireModule.initializeApp(firebaseConfig) , StoreModule.provideStore(reducer) , RouterModule.forRoot(routes) ... How would I reconfigure one of these at runtime? For example, user selects one of two links and different module is lazy loaded and configured differently... How can I pass data to this new NgModule? All I can think of is to put something in global scope and read it from there, but... doesn't feel right :) Providers can't be modified after the injector was created. You can create a service that

Angular2 - 'Can't resolve all parameters' error while injecting http into a custom service

删除回忆录丶 提交于 2019-12-03 14:40:48
问题 I have built an ErrorHandlerLogger which is a service which extends ErrorHandler and logs error messages into a remote repository. ErrorHandlerLogger requires the Angular http client provided by the HttpModule . In the ErrorHandlerModule I import HttpModule and define ErrorHandlerLogger as provider. In the AppModule I import ErrorHandlerModule . When I launch the app I get the following error message Uncaught Error: Can't resolve all parameters for ErrorHandlerLogger: (?). Here my code

Best approach to create recursive treeview dynamically from data API

时光怂恿深爱的人放手 提交于 2019-12-03 13:27:18
问题 I'm learning Angular 2, trying to build an expandable tree-view from a (potentially very large) third-party API. The API has an underlying structure like this: - Home (id: 1053) - - Rugby League (id: 1054) - - - Super League (id: 1103) - - - - Castleford Tigers (id: 1111) - - - - Catalans Dragons (id: 1110) - - - - Huddersfield Giants (id: 1116) - - - - Hull FC (id: 1108) - - - Championship (id: 1104) - - - - Batley Bulldogs (id: 1120) - - - - Bradford Bulls (id: 1118) - - - - Dewsbury Rams