search
HomeWeb Front-endJS TutorialBest practices for front-end cloud components based on AngularJS

AngularJS is a front-end development framework designed and developed by Google. It can help developers conduct front-end development more conveniently. AngularJS was designed to overcome the shortcomings of HTML in building applications. It is very comprehensive and easy to learn, so AngularJS quickly became the mainstream framework for JavaScript.

1. Amazing’s Angular

Features of AnguarJS

Convenient REST: RESTful has gradually become a standard way for servers and clients to communicate. You only need to use one line of javascript code to quickly get data from the server. AugularJS turns these into JS objects as Model, following the MVVM (modelview view-model) design pattern.

MVVM savior: Model will interact with ViewModel (through $scope object) and listen for changes in Model. It can be sent and rendered through View, and the code is displayed by HTML. Views can be controlled through $routeProvider objects, so you can deeply link and organize your Views and Controllers, turning them into navigation URLs. AngualrJS also provides a stateless Controller, which can be used to initialize and control the $scope object.

Data binding and dependency injection: Everything in the MVVM design pattern automatically communicates with the UI no matter what happens. This helps us remove wrappers, getter/setter methods or class definitions. AngularJS will help us handle all of this, and you can handle the data just like basic JavaScript data types. Of course, you can also handle complex data through customization. Because everything happens automatically, you don't have to call a main() to execute your code, but it is driven by dependencies.

Extensible HTML: Most websites are built using non-semantic

tags. You need to define the relevant DOM hierarchy yourself in the CSS class. With AngularJS, you can operate HTML like XML, and there are endless ways to complete tag and attribute definitions. AngularJS completes related settings through its own compiler and directives, which is also the cornerstone of component implementation.

When everyone comes into contact with jQuery, they find that they need to pre-bind and retrieve the data before stuffing it back. The process of stuffing needs to be taken care of. But with Angular, data retrieval is automatically completed by injecting variables, including event binding. Data binding, MVVM, and dependency injection make you feel that you don't need to care about many things in the past. You only need to pay more attention to the data structure and business layer. It frees us from the tedious DOM binding.

2. The road to componentization

Components are simple encapsulation of data and methods. Here, components with UI effects such as style classes, command types, methods, etc. are collectively referred to as components. In large-scale software, componentization is a consensus, which on the one hand improves development efficiency and on the other hand reduces maintenance costs.

Componentization and component presentation

There are many things that can be done with componentization, such as templating. Now the task of templating is handed over to the front end. The second is a public style library, the third is a public function library, some business components, and the modularity is a bit special.

The general presentation form of components includes: a unified style library, code snippets with a certain HTML structure, some functional functions controlled by JS, and certain data input and output controls.

3. Uncovering the cloud components

The concept of cloud and cloud components

Cloud is a metaphor for network and Internet. In the past, cloud was often used to represent telecommunications networks, and later it was also used to abstractly represent the Internet and underlying infrastructure.

Cloud services refer to obtaining required services through the network in an on-demand and easily scalable manner. Such services can be IT, software, Internet-related, or other services. It means that computing power can also be circulated as a commodity through the Internet. The combination of cloud and components constitutes cloud components. In the final analysis, we hope to control all N projects together through a unified control thing.

The component types of GeTui

The component types of GeTui include style components, command components, service components, public filters, public function libraries, etc.

From the component classification, you can find that the exclusive CSS is a style component. Adding a template is a very simple component. Then add a controller into it, which is the component with certain JS and certain logic mentioned earlier. Add link. Go in, bring the animation, and add the data layer to have certain input and output capabilities. This data layer may contain multiple types of data. It may interact with your page controller, or it may be a very powerful component that directly communicates with the server to obtain data and transfer data. (Of course, in actual practice, the former may be more suitable for our current environment. , the latter will have higher requirements for a unified interface).

The picture above is a technical solution for pushing cloud components. Based on the three major front-end components and some other libraries such as geofence components (we need to let Baidu Maps connect our entire project), there are also visualization projects, such as the flow of people in a scenic spot in Hangzhou during the G20 period. The visualization project will use third-party libraries . GeTui uses LESS to write CSS and develops cloud components based on these.

According to some situations of cloud components, it can be deduced that its best practice object is to start from a management system with certain common interactive table form classes, gradually include complex interactive system applications, and have certain support for responsiveness. GeTui started as a push service and later developed many product lines. There will be many 2B and 2C platforms for push services, which are managed.

Best practices for front-end cloud components based on AngularJS

Best practices for front-end cloud components based on AngularJS

The picture above is the directory structure used by the Tuiyun component. It is packaged with gulp. There is a wd folder in the CSS, which mainly contains some third-party libraries. The more important thing is the following, the same is true for JS, wd is the basic library. The fifth one is the most important. All components are placed under this folder. Each component contains its own three major components - template, logic, interaction, effect and style.

Gulp-based packaging

Best practices for front-end cloud components based on AngularJS

Cloud component display site

The users of cloud components are mainly divided into three categories. The first category is front-end users (including pan-front-end personnel), who need to learn how to use it quickly Use components (you must know some basic concepts and usage of Angular). The second category is UI designers, projects and products, etc. They need to observe whether the effect is suitable and design new such systems based on the library. The third category is tourists and other personnel.

New thinking about cloud components

Cloud components can affect the whole body. If the cloud component mechanism is not used well, for example, an old component is updated with a bug, it will have a lot of negative impacts. What should we do at this time?

Back to the beginning of the cloud, it is not difficult to find that when resources are isolated, this impact will not occur (cloud components use their reverse thinking to achieve convenience), then we can relatively close the cloud component resources Reduce this impact. This is version control. Different projects reference corresponding clouds to achieve the balance between the two just mentioned and optimize the results.

So, only with reasonable control can we truly take advantage of cloud components.

Under multiple versions, our development model is that the cloud component upgrade of a certain project is determined by the project. Because if the cloud component is released and all projects upgrade the cloud component, the cost of backtesting will be very high. Moreover, the original cloud component version is sufficient for the current version of the projects that have been launched before.

Project system diagram of GeTui

Best practices for front-end cloud components based on AngularJS

Problems in actual use

The release of cloud components has a certain periodicity, but the needs in actual projects need to be responded to quickly. In this case, the cloud component extension module needs to be used ( Mode) development: Develop the component-level modules of this project based on cloud components, and extend or customize the cloud components on a project basis.

4. Experience and summary about AngularJS

First, modularization: Be prepared to modularize abstraction at any time. This is a dynamic process.

Second, think more about the surroundings and the parts that exceed the limit - think from another perspective, facilitate the downstream, and work backwards to the upstream.

Third, there are no unachievable effects, only unbearable costs.

Fourth, there are many methods, you can try them all if time permits.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool