observable

Invoke component refresh in Angular 2

ぃ、小莉子 提交于 2019-12-19 04:25:10
问题 I am trying to implement a navbar that shows different links based on whether or not a user is logged-in. I am using the angular2-jwt library which provides the tokenNotExpired() function. I have 2 routes, /home and /login . I have a navbar component which is outside of the <router-outlet> , which means it is initialized only once and not every time the route changes. After successful login, I am invoking router.navigate(['/home]) . The home and login both have checks for if a user is logged

Angular2 ChangeDetection or Observable?

点点圈 提交于 2019-12-19 03:24:18
问题 I'm having difficulty with a component that doesn't refresh upon log in. The component is navbar.component that contains links to my pages/components. On it, there is a "login" link that renders login.component on which I can provide username and password and click the login button. login.component uses user.service which calls the backend with the username and password provided by login.component, stores the received token and redirects to '/'. At this point, the "login" link on navbar

Passing composite data in rxjs observable chains

孤街醉人 提交于 2019-12-19 02:06:31
问题 I have a block of code where I'm calling observables in a chain like so: getData().flatMap(results => { return callNextDataMethod(results); } .flatMap(results2 => { // next operation and so forth }) Now, I understand that flatMap will allow me to pass the results of the previous observable to the next one. However what I need is to both do that as well as pass the results on the first. Let's assume that I do some cleanup, validation, etc on the data that comes back in getData and I want that

How to cancel/revert changes to an observable model (or replace model in array with untouched copy)

给你一囗甜甜゛ 提交于 2019-12-18 14:00:11
问题 I have a viewModel with an observableArray of objects with observable variables. My template shows the data with an edit button that hides the display elements and shows input elements with the values bound. You can start editing the data and then you have the option to cancel. I would like this cancel to revert to the unchanged version of the object. I have tried clone the object by doing something like this: viewModel.tempContact = jQuery.extend({}, contact); or viewModel.tempContact =

Does Subject.complete() unsubscribe all listeners?

≯℡__Kan透↙ 提交于 2019-12-18 13:53:33
问题 I build a simple confirmation dialog service (Angular 2) with this method: confirm(body?: string, title?: string): Subject<void> { this.confirmation = new Subject<void>(); // ... show dialog here... "are you sure?" return this.confirmation; } _onYesClicked() { // ... closing the dialog this.confirmation.next(); this.confirmation.complete(); } _onNoClicked() { // ... closing the dialog this.confirmation.complete(); } Usage: confirmationService.confirm().subscribe(() => alert("CONFIRMED")); If

what triggered combineLatest?

不羁的心 提交于 2019-12-18 13:33:15
问题 I have a few observables. And I need to know which one triggered the subscribe. Observable.combineLatest( this.tournamentsService.getUpcoming(), this.favoriteService.getFavoriteTournaments(), this.teamsService.getTeamRanking(), (tournament, favorite, team) => { //what triggered combinelatest to run? }).subscribe() 回答1: Short answer is: You don't know. You could implement some workaround, however this is really ugly and I would recommend rethinking the usecase why you need this and maybe if

Knockout Filtering on Observable Array

≯℡__Kan透↙ 提交于 2019-12-18 12:45:09
问题 I've started learning Knockout and I'm having some trouble filtering an observable array on a button click and displaying the results. This is my model: function Product(data) { this.id = data.id; this.name = data.name; this.price = data.price; this.description = data.desc; this.image = data.image; this.genre = data.genre; this.show = data.show; this.offer_desc = data.offer_desc; this.offer_id = data.offer_id; } function ProductModel() { var self = this; self.products = ko.observableArray([])

Angular 4 - ERROR TypeError, ERROR CONTEXT DebugContext_

半腔热情 提交于 2019-12-18 12:17:06
问题 I'm rookie in Angular 4 and I need some help. My code in console display error but in my template everything display correct. Could someone help me understand what happend? Error ERROR TypeError: Cannot read property 'Tytul' of undefined NewsDetailsComponent.html:7 ERROR CONTEXT DebugContext_ {view: Object, nodeIndex: 12, nodeDef: Object, elDef: Object, elView: Object} news.ts export interface News { Ident: number; Tytul: string; Tresc: string; Data: string; } news.service.ts import {

How to get notified of a observer's unsubscribe action in a custom Observable in RxJava

*爱你&永不变心* 提交于 2019-12-18 11:46:39
问题 I'm trying to wrap some listener-pattern based API to an Observable. My code roughly looks like following. def myObservable = Observable.create({ aSubscriber -> val listener = {event -> aSubscriber.onNext(event); } existingEventSource.addListener(listener) }) However, I want my observable to immediately remove the listener from the underlying existingEventSource when the observer calls subscription.unscribe(). How could I achieve this goal? 回答1: The Subscriber abstract class actually has a

Unit testing an observable in Angular 2

拥有回忆 提交于 2019-12-18 10:58:37
问题 What is the correct way of unit testing a service returning an Observable result in Angular 2? Let's say we have a getCars method in a CarService service class: ... export class CarService{ ... getCars():Observable<any>{ return this.http.get("http://someurl/cars").map( res => res.json() ); } ... } If I try to write the tests in the following way I get the warning: 'SPEC HAS NO EXPECTATIONS': it('retrieves all the cars', inject( [CarService], ( carService ) => { carService.getCars().subscribe(