[英]Show title attribute when hovering then revert back to original text when not hovering
[英]Revert bound title attribute to parent title
這與像這樣的問題相反。
我在父元素中有一個子元素(在本例中為matSelect
中的matCard
,這可能無關緊要),並為父元素設置了title
。 子元素可能提供也可能不提供自己的title
:
<mat-card title="Parent title">
<mat-select [title]=getChildTitle()>
</mat-select>
</mat-card>
有什么我可以從getChildTitle()
返回以使其恢復為父title
文本的唯一方法,還是我可以這樣做以再次指定父標題的唯一方法,à la [title]=getChildTitle() ?? 'Parent title'
[title]=getChildTitle() ?? 'Parent title'
? 只是返回undefined
似乎並沒有這樣做 - 然后我的標題文本顯示為“undefined”。
您提供了有關如何傳入這些標題的一些背景信息。我假設您有一個將使用mat-card
和mat-select
的組件。
在 my-component.ts
@Component({
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['my-component.css'],
})
export class MyComponent{
@Input()
public parentTitle: string;
@Input()
public childTitle?: string;
public function getChildTitle() {
return this.childTitle ?? this.parentTitle;
}
}
在 my-component.html
<mat-card [title]="parentTitle">
<mat-select [title]=getChildTitle()>
</mat-select>
</mat-card>
在 app-component.html
<!-- this will use parent for both parent and child title -->
<my-component parentTitle="Parent"></my-component>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.