What is the equivalent of ngShow and ngHide in Angular 2+?

后端 未结 18 2457
离开以前
离开以前 2020-11-22 14:46

I have a number of elements that I want to be visible under certain conditions.

In AngularJS I would write

stuff
18条回答
  •  情书的邮戳
    2020-11-22 15:35

    If your case is that the style is display none you can also use the ngStyle directive and modify the display directly, I did that for a bootstrap DropDown the UL on it is set to display none.

    So I created a click event for "manually" toggling the UL to display

        
    

    Then on the component I have showDropDown:bool attribute that I toggle every time, and based on int, set the displayDDL for the style as follows

    showDropDown:boolean;
    displayddl:string;
    manualtoggle(){
        this.showDropDown = !this.showDropDown;
        this.displayddl = this.showDropDown ? "inline" : "none";
    }
    

提交回复
热议问题