ios - Ionic - iPhone X 状态栏覆盖共享标题组件
问题描述
我已经看到各种类似的帖子,其中 iOS 状态栏覆盖在应用程序的标题上。
我还没有看到另一个和我有同样问题的帖子。
我正在尝试为某些页面使用共享标题组件,当我使用它时,我遇到了覆盖问题。
我已经简化了代码并使用 ionic tabs starter 模板重新创建了我的问题:
<ion-header>
<shared-header title="Home - shared header"></shared-header>
</ion-header>
shared-header.component.html
<ion-navbar>
<ion-title>{{title}}</ion-title>
</ion-navbar>
shared-header.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'shared-header',
templateUrl: 'shared-header.component.html'
})
export class SharedHeaderComponent {
@Input('title') title: string;
constructor() { }
}
<ion-header>
<ion-navbar>
<ion-title>
About
</ion-title>
</ion-navbar>
</ion-header>
为什么会发生这种情况?是因为额外的<shared-header></shared-header>
标签吗?如果是这样,可以做些什么来解决这个问题?
解决方案
问题是由于组件标签位于标题标签内,由于某种原因,这会导致标题呈现不正确。我使用的解决方案是在标题中使用属性而不是组件标签。
在组件内部将选择器包裹在方括号中以定义它能够将其用作属性
shared-header.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: '[shared-header]',
templateUrl: 'shared-header.component.html'
})
export class SharedHeaderComponent {
@Input('title') title: string;
constructor() { }
}
然后在标题中,您可以将组件作为属性注入,如下所示
<ion-header shared-header title="Home - shared header">
</ion-header>
如果你想通过标签和属性访问你的组件,你可以定义多个选择器
@Component({
selector:'[shared-header], shared-header',
templateUrl: 'shared-header.component.html'
})
推荐阅读
- android - 重新发布被拒绝的android应用程序的正确方法
- kendo-ui - 剑道甘特图中的里程碑渲染
- google-cloud-storage - 如何等待 gcsfuse 写入(刷新)到 GCS 存储桶?
- c++ - 我可以在不同的 TU 中提供相同的函数定义吗
- python - 如何在 Django REST 框架中执行更新、删除操作
- google-chrome-extension - 如何将生成的用户 ID 传递到 chrome 扩展的搜索 URL?
- jsf - 用另一个模态 p:dialog 覆盖模态 p:dialog
- r - 使用 str_extract 提取美元金额
- terraform - 更改计数时的 Terraform 循环
- excel - 错误地使用 Right 函数