angular2-services

How do I create a singleton service in Angular 2?

对着背影说爱祢 提交于 2019-12-16 22:18:06
问题 I've read that injecting when bootstrapping should have all children share the same instance, but my main and header components (main app includes header component and router-outlet) are each getting a separate instance of my services. I have a FacebookService which I use to make calls to the facebook javascript api and a UserService that uses the FacebookService. Here's my bootstrap: bootstrap(MainAppComponent, [ROUTER_PROVIDERS, UserService, FacebookService]); From my logging it looks like

http provider Observable.toPromise() not working as expected in promise chains

…衆ロ難τιáo~ 提交于 2019-12-14 03:47:28
问题 If i call a promise enabled method using the ng2 http provider Observable.toPromise() support it works as expected but when i use it as part of promise chain it resolves the returned promise before the then handler has processed and returned the result. Any known issues with getting Observable.toPromise() to work in promise chains or alternative ways i might test to make it a promise chain compatible result? I'm blocked by this resolving promise before the http request, last item in promise

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

随声附和 提交于 2019-12-14 03:41:08
问题 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

Angular 2 navigating in the different instances of the same component with different data to display

三世轮回 提交于 2019-12-14 02:26:35
问题 I have a simple side menu in my Angular 2 applications which display a list of classRoom , each class Room has many users. I navigate between the different instance with routerLink . My problem is that when I click on the first item : -class Room number 1 I have no problem and the list of user are alright, but when I click on Class Room number 2 the data does not change, so the users displayed are the users of Class Room Number 2. How can I tell Angular To re-render the component with the new

Share services between multiple boostrapped component

不打扰是莪最后的温柔 提交于 2019-12-14 01:41:37
问题 I created 2 components which are boostrapped separately (in 2 different views), and I try to share a unique service (singleton) between these 2 components. The service is use to manipulate one of these component. My service : @Injectable() export class ModalContainerService { private component: ModalContainer; constructor() {} setComponent(component: ModalContainer) { this.component = component; <-- for holding the reference to my component } showFirst() { this.component.showFirst(); }

Angular 2: {{object}} works, {{object.child}} throws error

狂风中的少年 提交于 2019-12-14 00:47:39
问题 Been working with Angular v1 for some time now and since Angular v2 came in Beta, been playing around with that. Now I've got this piece of code, but can't get it to work, really don't know why. Somehow, when I print {{profileUser | json}} everything works fine (profileUser is an object). But when I want to print a child of that object (for example {{profileUser.name}} or {{profileUser.name.firstName}} ), Angular throws the following error: EXEPTION: TypeError: undefined is not an object

Angular 2 - Toggle button based on JSON response

这一生的挚爱 提交于 2019-12-13 22:38:41
问题 How can we toggle a button to Yes/No based on JSON response in angular 2? 回答1: Use following code to toggle button import {Component, NgModule, VERSION} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'my-app', template: ` <div> <button *ngIf='toggleButton' (click)='toggleButton = false'>Button One</button> <button *ngIf='!toggleButton' (click)='toggleButton = true'>Button Two</button> </div> `, }) export class App { name:string;

directive from shared module is not visible

泄露秘密 提交于 2019-12-13 21:48:48
问题 Trying to dive into angular 2 having some experience in angular 1 and having some puzzles. I made one shared module: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Constants } from './injectables/constants'; import { Utils } from "./injectables/utils"; import { HighlightDirective } from "./directives/highlight"; @NgModule({ imports: [ CommonModule ], declarations: [ HighlightDirective ], providers: [ Constants, Utils ], exports: [

Angular 2/5. Service with HttpClient makes mistake and doesn't works

孤人 提交于 2019-12-13 21:04:38
问题 I'm trying to make service which takes (trying to take) XML-file from remote server. I haven't enough experience to find mistakes by myself. Relevant code of app.component.ts : import { Component, OnInit, AfterViewInit, ElementRef, ViewChild, Renderer2 } from '@angular/core'; import { CanvasSettings } from './canvas-settings'; import { Rate } from './rate'; import { RateService } from './rates.service'; import { CBRRateService } from './cbrrates.service'; import { DatePoints, Year, Month, Day

Sending data between components using a service in Angular 2

允我心安 提交于 2019-12-13 16:25:52
问题 I'm trying to send data between two components using a service. However, I'm having trouble with the data populating when the 'child' component first loads. When you select a 'release' from the unordered list on the release-list.component, it will load the release-detail.component through a router-outlet. The release-detail.component should show the release artist. It works if you select a release and then select a release for a second time. But I'm having to 'load' the release-detail