[英]Ionic 4/ Angular 6 - getting data outside lifecycle hook from app.component
I have my navigation set up in my app.component.html
, and I would like to use an *ngIf
inside that template. 我在app.component.html
设置了导航,我想在该模板中使用*ngIf
。 However, since lifecycle hooks like ionViewWillEnter
, etc don't work in app.component.ts
, how can I trigger a call to fire every time the side nav is popped open? 但是,由于生命周期挂钩(例如ionViewWillEnter
等)在app.component.ts
中app.component.ts
,因此如何在每次侧面导航弹出时触发触发调用的操作?
I am just trying to get a red dot to show if there are notifications
in my array 我只是想让一个红点显示数组中是否有notifications
app.component.html app.component.html
...
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">
<ion-item [routerDirection]="'root'" [routerLink]="[p.url]">
<ion-icon slot="start" [name]="p.icon"></ion-icon>
=====>HERE===><div class="red-dot" *ngIf="p.title == 'Home' && notifications.length > 0"></div>
<ion-label>
{{p.title}}
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet main></ion-router-outlet>
...
app.component.ts app.component.ts
...
initializeApp() {
const parseQueryString = (queryString) => {
const query = <any>{};
for (let param of queryString.split('&')) {
const pair = param.split('=');
query[pair[0]] = pair[1];
}
return query;
};
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.deepLinks.route({
...
What I want to add to the side nav logic 我要添加到侧面导航逻辑的内容
const newData = await this.api.listModel('Notification', {
page: this.page
});
this.notifications = this.notifications.concat(newData);
this.notifications = _.filter(this.notifications, { isActioned: false }
As far as I understood this is same component. 据我了解,这是相同的组件。 You can try to call detectChanges() whenever notifications array is changed. 每当通知数组更改时,您都可以尝试调用detectChanges()。 More info here: https://angular.io/api/core/ChangeDetectorRef 此处提供更多信息: https : //angular.io/api/core/ChangeDetectorRef
If this is not same component, you can use service and Observables from Rxjs as proxies. 如果这不是相同的组件,则可以将Rxjs中的service和Observables用作代理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.