angular-services

Observable vs Subject and asObservable

主宰稳场 提交于 2019-11-30 05:19:24
I am learning RxJs, I am seeking confirmation or correction on my assumption. I am trying to make a public read only observable in a service that I can use .next() on in various places in my service class. I am wondering if this is the proper way to do it: private myObservable = new Subject<T>(); public myObservable$: Observable<T> = this.myObservable.asObservable(); The user can subscribe to myObservable$ I can use myObservable.next(...); It works perfectly but I am experience enough to know that I may just be being an unwitting idiot (RxJS is huge). Is this correct pattern and correct object

angularjs $httpProvider interceptor documentation

风格不统一 提交于 2019-11-30 03:30:49
I am new to angular (and programming), here is a seemingly simple question but I could not figure it out. some tutorials suggests using $httpProvider.interceptors.push('interceptorName') to manipulate the http request and response. I want to know more about the interceptor thing so I look at the official document, but I could not find anything related to interceptor, there are only a method (useApplyAsync([value]);) and a property (defaults) in $httpProvider ( docs ). I know from other tutorials that an interceptor is a regular service factory and I know how to use it, but my question is:

Angular 2 send data from component to service

大兔子大兔子 提交于 2019-11-29 18:37:17
问题 My target is to send data from Angular component to service and use service methods to work on it. Example: export class SomeComponent { public data: Array<any> = MyData; public constructor(private myService: MyService) { this.myService.data = this.data; } } and service: @Injectable() export class TablePageService { public data: Array<any>; constructor() { console.log(this.data); // undefined } } Getting data is undefined. How to make it works? 回答1: An example if interaction between service

AngularJS : Pass data from one view to another with in same controller

白昼怎懂夜的黑 提交于 2019-11-29 17:04:40
Summary : I have a form in view( first ) of my angular application and on success response from the ajax call on submit it redirects the user to the view( second ). There is only one controller for the application( for all view ). Here, user can enter the fields in the form from the view( first ) which should get displayed on the view( second ) & again there is a form in the view( second ) where user can enter the fields in the form which should get displayed on the view( third ). As all the views( first,second,third ) sharing the same controller function.I created one service to set & get the

How to send data from one component to another using a shared service [duplicate]

好久不见. 提交于 2019-11-29 14:26:51
This question already has an answer here: How to share service between two modules - @NgModule in angular not between to components? 5 answers Angular - shared service between components doesn't work 2 answers I wanted to send data using subject to another component (for a earning purpose). I am not able to fetch back the data. Here is my code: app.component.ts import { Component } from '@angular/core'; import { shareService } from './share.service'; @Component({ selector: 'my-app', template: ` <hello></hello> <button (click)="passData()"> Start </button> `, styleUrls: [ './app.component.css'

Angular http returns $$state object

大城市里の小女人 提交于 2019-11-29 02:55:10
问题 I have the following factory defined: angular.module("account").factory("users",["$http", function(a){ return { getUser: function(){ return a.get("/user/me").then(function(r){ return r.data; }); } }; } ]); And my controller: angular.module("test.controllers",["account"]) .controller("TestCtrl",["$scope","users", function(a,u){ a.user = u.getUser(); console.log(a.user); }]); Here's the console.log: d {$$state: Object, then: function, catch: function, finally: function} $$state: Object status:

Observable vs Subject and asObservable

巧了我就是萌 提交于 2019-11-29 00:48:12
问题 I am learning RxJs, I am seeking confirmation or correction on my assumption. I am trying to make a public read only observable in a service that I can use .next() on in various places in my service class. I am wondering if this is the proper way to do it: private myObservable = new Subject<T>(); public myObservable$: Observable<T> = this.myObservable.asObservable(); The user can subscribe to myObservable$ I can use myObservable.next(...); It works perfectly but I am experience enough to know

angularjs $httpProvider interceptor documentation

蓝咒 提交于 2019-11-29 00:37:38
问题 I am new to angular (and programming), here is a seemingly simple question but I could not figure it out. some tutorials suggests using $httpProvider.interceptors.push('interceptorName') to manipulate the http request and response. I want to know more about the interceptor thing so I look at the official document, but I could not find anything related to interceptor, there are only a method (useApplyAsync([value]);) and a property (defaults) in $httpProvider (docs). I know from other

How to test 'private' functions in an angular service with Karma and Jasmine

烈酒焚心 提交于 2019-11-28 22:39:00
I have a service in my angular app that looks something like this: angular.module('BracketService', []).factory('BracketService', [function() { function compareByWeight(a, b) { return a.weight - b.weight; } function filterWeightGroup(competitors, lowWeight, highWeight) { //filter stuff } function createBracketsByWeightGroup(weightGroup) { //create some brackets } //set some base line values var SUPER_HEAVY_WEIGHT = 500; var SUPER_LIGHT_WEIGHT = 20; return { //create brackets from a list of competitors returnBrackets: function(competitors) { var brackets = {}; //get super light weights brackets

get headers from get Http request in Angular

梦想与她 提交于 2019-11-28 14:19:32
I'm making a call to an API that gets blob data. back end sends to me also file name in header. My actual problem is that I can't get header from the api. Here's my service.ts public openFile(path) { let url='/download/'; let pathFile= new HttpParams().set('pathFile', path); return this.httpClient.get(url,{params:pathFile, responseType: 'blob' }); and in component.ts I call the service. when I try to print the res.headers I get undefined in console. openFile(path){ this.creditPoliciesService.openFile(path).toPromise().then (data => { console.log("dataaaaaa",data.headers); // undefined var blob