0

I have created a component and trying to pass boolean value inside it as @input which will help me to show/hide a div. But it is giving me undefined. can anyone please point out what is wrong in this?

Index.html

<abc-comp x="1" y="64" [showviewmore]="true"></abc-comp>

abc-comp.ts

  @Input() x = '';
  @Input() y = '';
  @Input() showviewmore : boolean;

abc-comp.html

  <div class="col-xs-4" *ngIf="showviewmore">
      //Some Content and tags
  </div>

1 Answer 1

1

try modified code below

<abc-comp x="1" y="64" [showviewmore]="true"></abc-comp>

abc-comp.tstry

@Input() x = '';
@Input() y = '';
@Input() showviewmore : boolean =false;
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @Divya, Thank you for posting it. I am able to pass the value. But still, ng-IF is not hiding the div even if the flag value is false. Am I making some mistake here?
@RiteshSingh your approach was correct only you have to define default value inside comp.ts. check updated code

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.