Analysis of encapsulation of scrolling list component in Angular 6
The content shared with you in this article is about the analysis of the encapsulation of the scrolling list component in Angular 6. It has certain reference value. Friends in need can refer to it.
Preface
Learning should be a process of combining input
and output
. This is the reason for writing this article.
In large screen display web APP, scrolling lists are often used. After several attempts, I settled on a pretty good idea.
Requirements
The thead part of the list header is static, while the tbody part scrolls upward.
After the body part is scrolled, the data needs to be refreshed. The final effect is to display all relevant data in the database in an upward scrolling form.
Analysis
If the amount of data is relatively small, we can take out all the data at once and put it into the DOM for circular scrolling. In fact, it is similar to the effect of a carousel.
But if there is a lot of data, doing so may cause a memory leak. Naturally, we can think of paginating the list data. My initial idea is to put a p
as a container on the outer layer of table
, and then table
periodically increases the top
value, etc. table
Halfway through the run, request data from the backend, dynamically create a component tbody
and insert it into table
, and then wait for the previous tbody
When you finish walking (out of sight), delete this component. The idea seemed feasible, but it ran into trouble in practice. When deleting the previous component, the height of table
will be reduced, and the table will instantly fall down. This is obviously not what we want, and the side effects are quite serious.
In this case, I separated tbody
into two table
, and the two table
loops. When there is no data under the previous table
, the second table
starts to walk, and waits for the first table
to completely walk outp
, reset its position to below p
, update the data, and then repeat the actions in between. It’s a little troublesome to complete, but the effect is passable and satisfactory. The problem is that the two timers are unstable. When I open other software and come back, the two tables run inconsistently. For this congenital disease, setInterval
is not accurate enough, and the two timers are prone to poor coordination.
Finally, on the way home from get off work, I thought of a method that didn't require two tables. Use only one table
to move up regularly. When halfway through, clear the timer, reset the position, and update half of the data. That is to say, the first half of the data in the array is removed, and the new data pulled from the background is spliced onto the array. In this way, the data can be continuously refreshed, and table
looks like it keeps going up.
Code
scroll-table.component.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
scroll-table.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
scroll-table.component.scss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
The effect of this is that the component only needs to pass in one parameter url
, and then all operations, including updating data, are completed by the component itself. This completes the component encapsulation and facilitates reuse.
Summary and Thoughts
1. Update data should be updated at the source, that is to say, do not add and delete DOM elements. This operation is troublesome and the performance is low. Putting it at the source means making a fuss about the array that stores the display data in the component class.
2. New data requested in the background should be prepared in advance and placed in another temporary array. It is equivalent to a cache and a temporary register.
3. I imagine the component as a function. It has only one parameter, which is the address of the data. As long as this parameter is present, the component can work normally and does not depend on any other value. Loose coupling.
4. Strengthen the idea of functional programming. Although this is the characteristic of React
, I always feel that angular
can also be used.
Related recommendations:
How to set AngularJs custom directives and the naming convention of custom directives
##In AngularJs What is the relationship between model, Controller and View? (Pictures and text)
The above is the detailed content of Analysis of encapsulation of scrolling list component in Angular 6. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.
