简体   繁体   English

重新分配在组件中作为@Input 出现的变量

[英]Reassign Variable which is coming as @Input in component

I have a component which takes a boolean value as @Input.我有一个将布尔值作为@Input 的组件。 I am controlling a div using ngIf with this value(to show/hide).我正在使用具有此值的 ngIf 控制 div(以显示/隐藏)。 Now, when I pass value true or false in both cases, the UI shows the div, whereas when not giving anything, it does not.现在,当我在这两种情况下传递值 true 或 false 时,UI 会显示 div,而当不提供任何内容时,它不会。 Am I missing something here?我在这里错过了什么吗?

Index.html索引.html

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

abc-comp.ts abc-comp.ts

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

abc-comp.html abc-comp.html

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

Also, I am trying to reassign the value of showviewmore variable in the ngOnInit() method but it never enters the if statement另外,我试图在 ngOnInit() 方法中重新分配 showviewmore 变量的值,但它从未进入 if 语句

  ngOnInit(): void {
   if(!this.showviewmore){
     this.showviewmore = newValue;
   }

Can anyone please help me?谁能帮帮我吗? Thanks in advance提前致谢

showviewmore="true" passes the value as string . showviewmore="true"将值作为string传递。 You have to modify [showviewmore]="true"您必须修改[showviewmore]="true"

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM