Using [hidden] instead of [ngIf] (Angular)

您所在的位置:网站首页 饭店用的香料白花叫什么 Using [hidden] instead of [ngIf] (Angular)

Using [hidden] instead of [ngIf] (Angular)

2024-01-20 11:00| 来源: 网络整理| 查看: 265

First of all, I need to explain the problem I have faced to look into this topic.

I had a hidden HTML input element that getting images and I have manually call the click function in a typescript method. So in my application, I have a cancel process that makes the page to its initial step, in there I am trying reset the value of the Input element as below,

(document.getElementById(‘importPhotoFileBrowser’) as HTMLInputElement).value = ‘’;

It worked! but, the thing is I am hiding the “Div” that contains the input element after some process completed to show another button instead of showing the import button to click the hidden input element manually. and previously I had used the [ngIf] to show and hide the div.

So what is happening****

The problem I have faced is the DOM element object is also getting removed when the [ngIf] is getting false and hiding whatever the element that you need. Then when I tried to set the value to null of the input element (that hidden in the Div that I have used the [ngIf] property) to remove the selected item its throwing errors to the console in the browser.

When using the [hidden] to show hide the elements it's not going to remove the DOM element object. It is only hiding the element by adding the CSS display: none. to the Element.

So this is the difference between using [ngIf] and [hidden] in angular to show hide any element.

I think this will help you a lot in the future.



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3