angular2-services

No provider for service error in angular2, why do I need to inject it in it's parent component?

强颜欢笑 提交于 2019-12-11 00:09:23
问题 I have a pages.service.ts import { Injectable } from '@angular/core'; import { ApiService } from '../../apiService/api.service'; import { Playlists } from '../shared/playlists.model'; @Injectable() export class PagesService { private currentPlaylists: Subject<Playlists> = new BehaviorSubject<Playlists>(new Playlists()); constructor(private service: ApiService) { } } This pages service needs another service called ApiService , I inject the way as shown above, it works. I bootstrap ApiService

How to extract JSON data from http.get in Angular 2 properly?

ε祈祈猫儿з 提交于 2019-12-10 23:15:29
问题 I can't seem to manage to make a variable for the view with the info from a json file but I'm so close. I can echo out the information in the .subscribe() -chain, but it won't set it to a variable, they just get undefined, what am I doing wrong? I just want to load my json file into a variable in the component view. It was easy in Angular 1. My service: import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import 'rxjs/add

angular2 - passing data object between components

别等时光非礼了梦想. 提交于 2019-12-10 19:34:11
问题 Looking for some help, if possible. I have a data object located in one component, received from a REST call. It contains user details that I would like to share across components, but I am having trouble. What is the best way to pass this object over to another component, so I can use the details? Ex. The data object is named user, and I want to share the user._id created from the database and received from the REST call with a separate component. Thanks everyone for any help. COMPONENT ONE

property map does not exist on observable response in angular

和自甴很熟 提交于 2019-12-10 18:37:55
问题 I am trying to build an angular 2 application using typescript in visual studio 2015 application. I am using angular release candidate 1. I have created a risk.service component which will provide data to my view. Trying to use observable. However I am getting the following error message in my visual studio editor property map does not exist on observable response risk.service.ts import { Injectable } from '@angular/core'; import { IRisk } from './risk'; import { Http, Response } from '

Angular 2 component less routing, executing whatever logic when particular URL is matched and redirect further

ⅰ亾dé卋堺 提交于 2019-12-10 18:25:51
问题 I'm using email service provider to which backend (microservice arhitecture) is sending various details that are needed to populate email dynamically. One of those details are links such as Deposit here link within an email where, when customer clicks on it he should be redirected to app directly to deposit page. How actual link looks like for example is: my-app.com/deposit?accountId=1&customerId=10&something=30 What data is passed to email service provider is: my-app.com/email-redirects?page

Angular 2 sibling components 2 way binding

那年仲夏 提交于 2019-12-10 18:13:05
问题 I am having 2 sibling components displayed at the same time to the user. One of them is a QuestionList which takes an array of questions from service and display list of questions. Once you click on a particular question it displays (next to the list) question details like seen below Question detail component uses router to take question id from the URL and stores it in a separate variable called selectedQuestion like this: selectedQuestion: Question; ngOnInit() { this.subscription = this

Angular 2 call service only on app initialization

谁说我不能喝 提交于 2019-12-10 16:02:48
问题 What I am trying to accomplish is to call external API only once per app initialization. I have a simple service, @Injectable() export class XService { url = "http://api.example.com" constructor(private _http:Http) { } callAnAPI(){ console.log('made an external request"); return this._http.get(url) .map(res=>res.json()); } } and two components, the main appComponent @Component({ selector: 'my-app', template: ` <div> Test </div> ` }) export class AppComponent { isLoading = true; results = [];

Service events do not affect template correctly

前提是你 提交于 2019-12-10 15:44:33
问题 Auth in google, use Angular2. First, in HTML, I load google api library: //index.html //... <script> var googleApiClientReady = function() { ng2Gauth.googleApiClientReady(gapi); } </script> <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script> //... After in Angular2 service I handle google auth data and emit event to inform component if google api is ready: //google auth service .ts import {Injectable, EventEmitter} from 'angular2/core'; @Injectable()

Angular2 observable share is not working

夙愿已清 提交于 2019-12-10 15:24:48
问题 Angular2 Observable share is not working and duplicate http calls going BuildingService.ts @Injectable() export class BuildingService { constructor(private http: Http){ } buildings$: Observable<Building[]>; this.buildings: Building[]; getData() : Observable<Building[]>{ this.buildings$ = this.http.get('http://localhost:8080/buildings').share().map(this.extractData); this.buildings$.subscribe(buildings => this.buildings = buildings); return this.buildings$; } private extractData(res: Response)

Force service instantiation in Angular 2 sub-module (an alternative to AngularJS run block)

℡╲_俬逩灬. 提交于 2019-12-10 13:17:22
问题 I have a service in sub-module that wraps some third-party module, instantiates and initializes its service to prepare for use within app. @Injectable() class SubmoduleInitializerService { constructor (thirdPartyService: ThirdPartyService) { thirdPartyService.initialize(...); ... } } @NgModule({ imports: [ThirdPartyModule], exports: [ThirdPartyModule], providers: [ ThirdPartyService, SubmoduleInitializerService ] }) class AppSubmodule {} ThirdPartyService isn't injected in app directly but is