Import {fromEvent} from ‘RXJS ‘; NgOnInit () {fromEvent(window, ‘resize’).subscribe((event) => {console.log(‘ If you change the screen size with the mouse, this will trigger this subscription. ‘); }); } This code uses the Angular2+ RxJS wrapper fromEvent() method to listen for resolution changes on the home page. We subscribe() to get events, and within the method body we can do whatever we want to do when the home page resolution changes. Ok, if you’re new to Angular2 +, welcome, you’re getting a quick technical lesson here. If you have time, you can continue to learn about Observable and RxJS theory. If you’re already an Angular2 + developer, you don’t need to read any further. I recommend you check out the Angular official for more details.
Observables allow messages to be passed between publishers and subscribers in an application. Observable objects have significant advantages over other techniques when event handling, one-step programming, and handling multiple values are required. Observables are declarative – that is, although you define a function to publish values, the function is not actually executed until a consumer subscribs to it. After the subscription, the subscriber is notified when the function completes or unsubscribes.
RxJS library responsive programming is an asynchronous programming paradigm for data flow and change propagation. RxJS is a library for reactive programming with observables that makes it easier to combine asynchronous and callback-based code. RxJS provides an implementation of the Observable type, which is necessary until an Observable is part of the JavaScript language and supported by browsers. The library also provides utility functions for creating and working with observables. These utility functions can be used to: (1) convert existing asynchronous code into observable objects; ② Each value in the iteration flow; Map these values to other types. (4) filtration for convection; ⑤, combine multiple streams. RxJS provides operators that are helpful to developers, such as map(), filter(), concat(), and flatMap(). We will focus on these operators in future articles.