I'm attempting to initiate repeated client-side action within OnInit
of an Angular 4 component using an IntervalObservable
. The application uses ASP.NET Core.
The observable subscription is executed. However, server-side prerendering in Microsoft.AspNetCore.NodeServices
appears to be executing the subscription -- never returning the rendered page to the browser.
What am I doing wrong here? Below are the steps to reproduce. In this sample I'm just trying to console.log
a heartbeat in the browser.
Steps to reproduce
- Create and
cd
into a new directory. - Run
dotnet new angular
. - Run
npm install
. - Replace the contents of
ClientApp/app/components/home/home.component.ts
with the code snippet below. - Run
dotnet run
and go to http://localhost:5000.
import { Component, OnInit } from '@angular/core';
import { IntervalObservable } from "rxjs/observable/IntervalObservable";
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {
ngOnInit(): void {
IntervalObservable.create(1500).subscribe((iteration:number)=>console.log(iteration));
}
}
When the request comes in, the debug console begins reporting the iteration
, as shown in the code snippet. The page renderer times out and eventually return an error page, but the IntervalObservable
subscription continues to iterate in the debug console.