Home Web Front-end JS Tutorial Introduction to methods to solve browser compatibility issues in Angular

Introduction to methods to solve browser compatibility issues in Angular

Dec 04, 2020 pm 05:39 PM
angular compatibility front end

How to solve the browser compatibility problem in

angular? The following article will introduce it to you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Introduction to methods to solve browser compatibility issues in Angular

Related tutorial recommendations: "angular tutorial"

Question: edge Under the browser, the border of the fixed column disappears

Cause: The ng-zorro-antd table component uses the nzLeft and nzRight instructions to fix the table columns. These two instructions Implement tags in css3:

position: -webkit-sticky !important;
position: sticky !important;
Copy after login

Google, Firefox and -webkit-kernel browsers all support this attribute (css3). IE does not support this attribute, so in IE, it will be automatically downgraded and the table will be empty. Fixed column, slideable form.
Edge browser uses the chromium kernel in versions after 1703, which has better support for CSS3 attributes and also supports the sticky attribute. It can be used and fixed table columns, but the border will disappear.

Solution:
The currently feasible solutions are as follows:

  1. Do not use fixed columns. If the product If there is no explicit requirement to use fixed columns, you can abandon the use of nzLeft and nzRight to fix the table. This makes the display effect consistent across browsers.

    For Edge browser downgrade processing, the effect is consistent with IE browser, there are no fixed columns, and the whole can be scrolled horizontally.

  2. Customize the fixed column implementation, do not use the fixed column implementation of the component, and implement the fixed column of the table by using position: absolute;.

The detailed process of the second plan is as follows:

Use p to wrap the table. When the width of the table exceeds the width of p, enable scrolling:

.scroll-table {
  width: 100%;
  overflow-x: scroll;
}
Copy after login

For the table, We can specify a width that exceeds the outer p width (so you can see the scrolling effect).

.fixed-table {
  width: 1300px; /* 可由th,td动态扩充,也可指定宽度 */
  border-collapse: collapse;
}
Copy after login

The last and most core issue is the implementation of fixed columns. It is very simple. Set a column of the table to absolute positioning. After setting the absolute positioning, the column will be separated from the original document flow. The table There is one missing column, so a background panel needs to be added to ensure that the table can leave a place for this fixed column.

The HTML code is roughly as follows. This fixed-col can be the style of a fixed column, or it can be set to the style of the background panel. In the demo, it is used to specify the style of the fixed column.

<p class="scroll-table">
    <table class="fixed-table">
        <thead>
            <tr>
                <th>无效背景板</th>
                <th class="fixed-col">固定列</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>无效背景板</td>
                <td class="fixed-col">固定列</td>
            </tr>
        </tbody>
    </table>
</p>
Copy after login

Reference code: Ironape


Problem: The Edge browser’s calendar (nz-range-picker) confirmation button needs to be clicked Twice

Cause: Not yet clear

Solution:

  1. Upgrade component version. Currently, this problem does not occur in versions above ng-zorro-antd 8.5.
  2. Custom footer Add an additional footer to replace the OK function. There are two ways to achieve this:
    Only cover the corresponding button, such as the OK button, At this time, the style of the button is inconsistent with the default footer button. To maintain consistency, you can customize the style, or you can directly use the style of the button in the default footer. In the following example, you choose to directly use the style of the component library: ant-calendar -ok-btn, the second step is to overwrite the original button. You can use absolute positioning to achieve overwriting:
<nz-range-picker [nzRenderExtraFooter]="renderExtraFooterTpl">
<ng-template #renderExtraFooterTpl>
  <p>
    <button nz-button nzType="primary" class="ant-calendar-ok-btn abs-right">确 定</button>
  </p>
</ng-template>
Copy after login

Corresponding css:

.abs-right {
  position: absolute;
  right: 12px;
  top: 7px;
  z-index: 1;
  box-shadow: none;
}
Copy after login

Delete the default footer, Completely customizable footer. At this time, you need to delete the original footer. You can delete the default footer through:

::ng-deep .ant-calendar-footer-btn {
  display: none;
}
Copy after login
. At this time, the additional footer cannot use absolute positioning.

Problem: Under IE browser, when switching between multiple tab pages, the height of the container where echart is located collapses

Cause: The height of the parent element cannot be dynamically adjusted under the IE browser (that is, the height is dynamically changed through the child elements)

Solution: Fixed the height of the container where the echart chart is located


## Problem : Under IE browser, when the form is initialized, form validation is triggered

Cause: This is a problem with IE. IE10 implements the input event, but the triggering time is wrong. For example, when the placeholder is changed, it will be triggered when the text of the placeholder is not in English. Edge15 fixed this problem, but IE may never fix this problem.

solution:

  1. 使用表单的reset()重置表单,但是重置的操作需要放在setTimeout中,或者通过其他手段将重置的操作作为表单初始化时的最后一个宏任务执行。这种方式经验证,最终的效果是,初始化表单后,表单输入元素的边框闪烁(红色)一下。
  2. 使用自定义的服务商插件(较为推荐),这种方式对原有代码的破坏性小(遵循了OCP原则),该插件是由DerSizeS提供的。只需要在对应的module中增加一个服务商即可
@NgModule({
    providers: [{
        provide: EVENT_MANAGER_PLUGINS, multi: true,
        useClass: UniqueInputEventPlugin, deps: [UNIQUE_INPUT_EVENT_PLUGIN_CONFIG],
    }]    
})
class MyModule {}
Copy after login
需要注意的是,插件需要自己添加到项目文件中(根据angular团队所说,这个插件修复了一个IE10或者IE11的bug,但是提交了太多的代码,这会给增加现有的应用的打包体积,虽然后面关于这个PR讨论了挺久,但是看样子是准备把这个放到FAQ里面,而不会把他并入框架),并在对应的模块中引用。

另注:IE的输入框会因为placeholder为中文而触发表单验证,placeholder改变了也会触发表单验证,所以,有一个讨巧的方法,placeholder里面的内容写成英文形式(推荐),但这显然不符合中文产品的需求,而且这显然没有国际化。所以可以想办法绕过这一条,使用 HTML实体(已验证,可行),Unicode编码(不可以)

更多编程相关知识,请访问:编程入门!!

The above is the detailed content of Introduction to methods to solve browser compatibility issues in Angular. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to install Angular on Ubuntu 24.04 How to install Angular on Ubuntu 24.04 Mar 23, 2024 pm 12:20 PM

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

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

Can I use Bluetooth headphones in airplane mode? Can I use Bluetooth headphones in airplane mode? Feb 19, 2024 pm 10:56 PM

With the continuous development of modern technology, wireless Bluetooth headsets have become an indispensable part of people's daily lives. The emergence of wireless headphones frees our hands, allowing us to enjoy music, calls and other entertainment activities more freely. However, when we fly, we are often asked to put our phones in airplane mode. So the question is, can I use Bluetooth headphones in airplane mode? In this article, we will explore this question. First, let’s understand what airplane mode does and means. Airplane mode is a special mode for mobile phones

Angular components and their display properties: understanding non-block default values Angular components and their display properties: understanding non-block default values Mar 15, 2024 pm 04:51 PM

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.

How compatible is the Go language on Linux systems? How compatible is the Go language on Linux systems? Mar 22, 2024 am 10:36 AM

The Go language has very good compatibility on Linux systems. It can run seamlessly on various Linux distributions and supports processors of different architectures. This article will introduce the compatibility of Go language on Linux systems and demonstrate its powerful applicability through specific code examples. 1. Install the Go language environment. Installing the Go language environment on a Linux system is very simple. You only need to download the corresponding Go binary package and set the relevant environment variables. Following are the steps to install Go language on Ubuntu system:

WIN10 compatibility lost, steps to recover it WIN10 compatibility lost, steps to recover it Mar 27, 2024 am 11:36 AM

1. Right-click the program and find that the [Compatibility] tab is not found in the properties window that opens. 2. On the Win10 desktop, right-click the Start button in the lower left corner of the desktop and select the [Run] menu item in the pop-up menu. 3. The Win10 run window will open, enter gpedit.msc in the window, and then click the OK button. 4. The Local Group Policy Editor window will open. In the window, click the [Computer Configuration/Administrative Templates/Windows Components] menu item. 5. In the opened Windows component menu, find the [Application Compatibility] menu item, and then find the [Remove Program Compatibility Property Page] setting item in the right window. 6. Right-click the setting item, and in the pop-up menu

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

Detailed explanation of win11 compatibility issues with win10 software Detailed explanation of win11 compatibility issues with win10 software Jan 05, 2024 am 11:18 AM

The software in the win10 system has been perfectly optimized, but for the latest win11 users, everyone must be curious about whether this system can be supported, so the following is a detailed introduction to the win11 software that does not support win10. Come and find out together. Does win11 support win10 software: 1. Win10 system software and even Win7 system applications are well compatible. 2. According to feedback from experts who use the Win11 system, there are currently no application incompatibility issues. 3. So you can upgrade boldly with confidence, but ordinary users are advised to wait until the official version of Win11 is released before upgrading. 4. Win11 not only has good compatibility, but also has Windo

See all articles