![](/img/trans.png)
[英]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.