我有一個將布林值作為@Input 的組件。我正在使用具有此值的 ngIf 控制 div(以顯示/隱藏)。現在,當我在這兩種情況下傳遞值 true 或 false 時,UI 會顯示 div,而當不提供任何內容時,它不會。我在這里錯過了什么嗎?
索引.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>
另外,我試圖在 ngOnInit() 方法中重新分配 showviewmore 變數的值,但它從未進入 if 陳述句
ngOnInit(): void {
if(!this.showviewmore){
this.showviewmore = newValue;
}
誰能幫幫我嗎?提前致謝
uj5u.com熱心網友回復:
showviewmore="true"將值作為 傳遞string。你必須修改[showviewmore]="true"
<abc-comp x="1" y="64" [showviewmore]="true"></abc-comp>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489889.html
標籤:javascript 有角度的 用户界面 前端 角11
上一篇:在按鈕后出現的文本中添加滾動條
下一篇:接受在反應中的檔案型別中不起作用
