angular2-observables

Change detection doesn't run when loading auth2 from Google API

不想你离开。 提交于 2019-12-24 00:09:34
问题 I'm trying to load the script https://apis.google.com/js/api.js?onload=initGapi from within an Angular 2 service in order to make calls to the Google API, but whenever I try to return a value when the script is done loading and initializing, the async pipe doesn't want to render the value to the template. I'm using an EventEmitter that fires when the gapi.load() and gapi.client.init is complete, and the observable is subscribed to it in a component. The async pipe doesn't seem to want to read

observable subscription does not work when written in ngOnit() in IE

巧了我就是萌 提交于 2019-12-23 11:46:22
问题 I have defined a behavior subject: component.ts bsub1: BehaviorSubject<Array<any>> = new BehaviorSubject(null); And called next() on it: html: <button (click) = getData()>Data</button> component.ts: getData() { getSomething(value, bsub1); } service.ts getSomething(value, _observable) { //do something _observable.next(retun) somevariable.map(p => { return { "a": value1, "b": value2 } }); } And made a subscription: component.ts ngOnInit() { bsub1.subscribe(list=>{ console.log("subscribed to

observable subscription does not work when written in ngOnit() in IE

落花浮王杯 提交于 2019-12-23 11:46:14
问题 I have defined a behavior subject: component.ts bsub1: BehaviorSubject<Array<any>> = new BehaviorSubject(null); And called next() on it: html: <button (click) = getData()>Data</button> component.ts: getData() { getSomething(value, bsub1); } service.ts getSomething(value, _observable) { //do something _observable.next(retun) somevariable.map(p => { return { "a": value1, "b": value2 } }); } And made a subscription: component.ts ngOnInit() { bsub1.subscribe(list=>{ console.log("subscribed to

Subscribe method don't react to changes [Angular 2]

岁酱吖の 提交于 2019-12-23 10:18:30
问题 I've got the method in my app.component that changes languages in my LangService. When the change occurs the LangService should then response with Observable object to all my other components as I have subscribed to changes in all my components. Unfortunately, it's not happening. It only response to the app.component that called the function for changing the language. I'm not sure where I have made a mistake. Maybe I'm just misunderstanding the whole concept as I'm new to Angular. Here is the

Pass Observable data from Parent Component to a Child Component created with componentFactoryResolver in Angular 2+

廉价感情. 提交于 2019-12-21 17:47:30
问题 I need help as I am a bit lost right now. So, I have a component that dynamically injets a child component into its template using componentFactoryResolver , here is my HTML <div class="dialog"> <div #container></div> <button (click)="move('back')">Back</button> <button (click)="move('forwards')">Forwards</button> </div> also in my component I have an observable that captures the click of the buttons like so, here is my (edited / reduced) code // parent-component.ts @ViewChild('container',

angular2 / RxJS - how to retry from inside subscribe()

老子叫甜甜 提交于 2019-12-21 17:35:13
问题 this is my code: this._api.getCompanies().subscribe( res => this.companies = JSON.parse(res), exception => {if(this._api.responseErrorProcess(exception)) { // in case this retured TRUE then I need to retry() } } ) in case an exception happened, it will be sent to a function in the API then return true if the problem is fixed (like token refreshed for example) and it just needs to retry again after its fixed I could not figure out how to make it retry. 回答1: In your .getCompanies() call right

Angular - what is the preferred way to terminate Observables?

谁都会走 提交于 2019-12-21 09:33:50
问题 From my understanding of Angular and RxJs there are two ways to terminate Observables. You can unsubscribe() from them or use takeUntil() and complete() . Below are examples of each approach (in pseudocode). The unsubscribe() approach private _id: number; private _subscriptions: Subscription[] = []; constructor(private _route: ActivatedRoute) { this._getId(); } public ngOnDestroy(): void { this._subscriptions.forEach( subscription => subscription.unsubscribe() ); } private _getId(): void {

'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

柔情痞子 提交于 2019-12-21 08:50:12
问题 I am trying to learn reactive programming using RxJS. I was trying to create an observable from an array using Observable.from() method, but I am getting an error: Property 'from' does not exist on type 'typeof Observable' I scaffolded an Angular application using Angular CLI, so all the dependencies including RxJS package was imported correctly. In app.component.ts I added below import statements: import { Observable} from 'rxjs/Observable' import 'rxjs/observable/from' And my AppComponent

Returning value from subscription typescript

只谈情不闲聊 提交于 2019-12-21 05:43:07
问题 How would i return success from Save() method. public SaveItem() { if(save()){ // The goal is to use save method like this // Close pop up; } public SaveAndNew() { if(save()){ // The goal is to use save method like this // Create new item; } private save() { let issuccess = false; this.myservice.AddParty(newUserObject) .subscribe(data => { if (data['status'].toString() === '1') { return issuccess = false; } else { return issuccess = true; } }, (er) => { return issuccess = false; }); } If i

What to return in the angular 2 async validator when using observables

不羁岁月 提交于 2019-12-21 01:59:08
问题 What do I have to return in the customerNameValidator if the async validation fails/succeeds that my 'customerName' FormControl is invalid? this.customerForm = this.formBuilder.group({ customerName: [this.newCustomerName, [Validators.minLength(2), Validators.required],[this.customerNameValidator.bind(this)]] }); customerNameValidator(c: AbstractControl) { return this.service.customerExists(c.value,this.companyId).subscribe(response => { if(response == true) { alert("true"); } else { alert(