Skip to content

Observable updates aren't reflected in templates #112

@paztis

Description

@paztis

This is a...

  • feature request
  • bug report
  • usage question

What toolchain are you using for transpilation/bundling?

  • @angular/cli
  • Custom @ngTools/webpack
  • Raw ngc
  • SystemJS
  • Rollup
  • Other

Environment

NodeJS Version: 12.13.1
Typescript Version: 3.7.5
Angular Version: 9.0.1
@angular-redux/store version: 10.0.0
@angular/cli version: (if applicable)
rxjs: 6.5.4
OS: Windows

Link to repo showing the issus

(optional, but helps a lot)

Expected Behaviour:

In below sample, redux observable updates are not displayed in the templates.
state.loader.counter is a number that is increased each second.
The console log well display the new value each second.

We only see the first value on the screen

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ loaderCounter$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
    this.loaderCounter$.subscribe((counter) => {
      console.log('----counter', counter)
    })
  }

  @select((state) => {return state.loader.counter}) loaderCounter$: Observable<number>;
}

If I replace the select decorator with a classic selector in the ngOnInit, result is the same

If I put a classic Observable, rendering is working correctly

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ classicObservable$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
  }

  classicObservable$ = new Observable<number>(observer => {
    let counter = 0;
    observer.next(counter);

    setInterval(() => {
      counter++;
      observer.next(counter);
    }, 1000);
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions