-
Couldn't load subscription status.
- Fork 13.4k
Description
Bug Report
Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.0.6
Ionic Framework : @ionic/angular 4.0.0-beta.2
@angular-devkit/core : 0.7.3
@angular-devkit/schematics : 0.7.3
@angular/cli : 6.1.3
@ionic/ng-toolkit : 1.0.6
@ionic/schematics-angular : 1.0.4
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0, ios 4.5.5
System:
Android SDK Tools : 25.2.5
ios-deploy : 1.9.2
ios-sim : 6.1.2
NodeJS : v8.9.4 (/Users/dtaalbers/.nvm/versions/node/v8.9.4/bin/node)
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Environment:
ANDROID_HOME : /usr/local/Cellar/android-sdk/24.4.1_1
Describe the Bug
I am trying to generate tabs based of the roles the current user has. Can't bind property to name of the ion-router-outlet component. I tried both
<ion-router-outlet name="{{tab.name}}"></ion-router-outlet>
and
<ion-router-outlet [name]="tab.name"></ion-router-outlet>
When I remove the name binding of the outlet component I get the following error
Error: Cannot find a differ supporting object '[object HTMLElement]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
This error can be fixed with a pipe explained here but its still doesn't iterate over my tabs.
Related Code
My viewmodel
export class TabsPage extends BaseComponent implements OnInit {
private availableTabs: any[] = [
{
label: 'Collecties',
name: 'pictures',
icon: 'images',
href: '/tabs/(pictures:pictures)',
roles: [
UserRoles.ReadPictures
]
},
{
label: 'Profiel',
name: 'my-profile',
icon: 'person',
href: '/tabs/(my-profile:my-profile)',
},
{
label: 'Over',
name: 'about',
icon: 'phone-portrait',
href: '/tabs/(about:about)',
}
];
private tabs: any[] = [];
public async ngOnInit(): Promise<void> {
await super.ngOnInit();
this.generateTabs();
}
private generateTabs(): void {
for (const tab of this.availableTabs) {
if (!tab.roles) {
this.tabs.push(tab);
} else {
if (tab.roles.some(x => this.currentUser.roles.some(y => y === x))) {
this.tabs.push(tab);
}
}
}
}
}
View:
<ion-tabs *ngIf="tabs.length > 0" #tabs color="primary">
<ion-tab label="Home" icon="home" href="/tabs/(home:home)">
<ion-router-outlet name="home"></ion-router-outlet>
</ion-tab>
<ion-tab *ngFor="let tab of tabs" [label]="tab.label" [icon]="tab.icon" [href]="tab.href">
<ion-router-outlet name="{{tab.name}}"></ion-router-outlet>
</ion-tab>
</ion-tabs>
Expected Behavior
I expect to be able to bind to the name property and iterate the tabs array to generate tabs.