0

When I update this.showPlan = true; i guess it is not updatiing globally because when clicking on document it is still showing as false instead of true

This is my HTML code:

<li (click)="displayPlanWidget()"></li>
<div style="display: none;" id="planTabInput">----</div>

This is my type script code:

public showPlan:boolean = false;     //For showPlan

ngOnInit() {
    var arg1 = this.showPlan;
    var arg2 = this.showAccount;

    console.log('arg1--------'+arg1); //coming fine on initial
    jQuery(document).click({showPlan:arg1},function(e) {
        console.log('showPlan--------'+e.data.showPlan); //coming as false insted true

        if(e.data.showPlan != 'false') { //this should trigger (not triggering because it is not updating to true)
            jQuery("#planTabInput").css( "display",'none' );
        }
    });
}


public displayPlanWidget() {
    this.showPlan = true;

  console.log('showPlan Changed to '+this.showPlan); //coming true(fine) 

  jQuery("#planTabInput").show();
}

Where I am doing wrong help is appreciated.

3

1 Answer 1

2

This is really all you need for the functionality you need to implement. Angular recommends avoiding direct DOM manipulation

<li (click)="displayPlanWidget()"></li> <div [hidden]="!showPlan" id="planTabInput">----</div>

import { Output, EventEmitter } from '@angular/core';

public showPlan = false;     //For showPlan
public showAccount = true; //For showAccount
@Output('activeWidget') activeWidget = new EventEmitter<string>();

public toggleWidget() {
    this.showPlan = !this.showPlan;
    this.showAccount = !this.showAccount;
    this.activeWidget.next((this.showAccount ? 'showAccount' : 'showPlan'))
}
Sign up to request clarification or add additional context in comments.

3 Comments

how it's known to other components.?
@mehany apart from toggle I want Popup should be closed when I click outside of the both popup's
If you need some UI components, you probably better off using existing community modules and read the docs. Consider this project for example github.com/akveo/ngx-admin, you can learn a lot from it and reuse its components

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.