I made a carousel effect through the RXJS's interval timing to change parameter.
I found that it works in development mode(ng serve), but it does not work properly in the universal
mode, It's can't enter the page.
For example:
n: number = 0;
max: number = 5;
constructor(){}
ngOnInit() {
this.carousel();
}
carousel() {
this.subscription = interval(2000).subscribe(() => {
//In universal, the console.log message show in node.js background log message not in browser console message. Each time the page is reorganized, it will be executed once and cannot be destroyed.
console.log(`show the photo: ${this.n}`);
if (this.n>this.max){
this.n = 0;
}else{
this.n = this.n+1;
}
}
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
I found in universal
model, assume that the carousel effect is on the page B
, you can successfully enter page B through the link on page A
, but opening page B directly will fail.
I tried to start the carousel in ngAfterContentInit()
and it doesn't work.
Reactive Extensions for JavaScript, or RxJS, is a JavaScript library that uses observables for reactive programming. It can be used with other JavaScript libraries and frameworks, and it integrates well into Angular. Today, we will discuss RxJS and Angular, the benefits of using RxJS in Angular, and how to use them together.
Angular Universal is an open-source project that extends the functionality of @angular/platform-server. The project makes server-side rendering possible in Angular. This article will discuss the issues and possible solutions we encountered while developing a real application with Angular Universal.
$interval will repeat a function call or a block a specified number of times with a delay in-between. This is what I would like to do, written in AngularJS:
The project makes server-side rendering possible in Angular. Another package Socket Engine is a framework-agnostic that theoretically allows any backend to be connected to an SSR server. This article will discuss the issues and possible solutions we encountered while developing a real application with Angular Universal and Express.
If you use angular universal, you need to use isPlatformBrowser
to exclude code that can only run on the front end.
Eaxmple:
import { isPlatformBrowser } from '@angular/common';
import { PLATFORM_ID } from "@angular/core";
constructor(
@Inject(PLATFORM_ID) private platformId: Object
) { }
do(){
if (isPlatformBrowser(this.platformId)) {
//do something, only runs on the front end
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With