[英]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.