Changing the order of Angular mat-tabs
I am using mat-tabs from Angular Material and I need to create the tabs dynamically depending on some conditions.
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Depending on some condition, I need to be able to generate the tabs like this for example:
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Is there a setting on the MatTabs API or some trick I can do from JavaScript to achieve this? Thanks!
angular angular-material
add a comment |
I am using mat-tabs from Angular Material and I need to create the tabs dynamically depending on some conditions.
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Depending on some condition, I need to be able to generate the tabs like this for example:
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Is there a setting on the MatTabs API or some trick I can do from JavaScript to achieve this? Thanks!
angular angular-material
Not really tried this, but maybe there's something you can do working with theselectedIndexfrom the API
– IvanS95
Nov 14 '18 at 14:22
add a comment |
I am using mat-tabs from Angular Material and I need to create the tabs dynamically depending on some conditions.
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Depending on some condition, I need to be able to generate the tabs like this for example:
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Is there a setting on the MatTabs API or some trick I can do from JavaScript to achieve this? Thanks!
angular angular-material
I am using mat-tabs from Angular Material and I need to create the tabs dynamically depending on some conditions.
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Depending on some condition, I need to be able to generate the tabs like this for example:
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab id="tab1" label="Second tab">
// Tab content
</mat-tab>
<mat-tab id="tab0" label="First tab">
// Tab content
</mat-tab>
<mat-tab id="tab2" label="Third tab">
// Tab content
</mat-tab>
<mat-tab-group>
Is there a setting on the MatTabs API or some trick I can do from JavaScript to achieve this? Thanks!
angular angular-material
angular angular-material
edited Nov 14 '18 at 15:07
mruanova
1,50921127
1,50921127
asked Nov 14 '18 at 14:04
decebaldecebal
218414
218414
Not really tried this, but maybe there's something you can do working with theselectedIndexfrom the API
– IvanS95
Nov 14 '18 at 14:22
add a comment |
Not really tried this, but maybe there's something you can do working with theselectedIndexfrom the API
– IvanS95
Nov 14 '18 at 14:22
Not really tried this, but maybe there's something you can do working with the
selectedIndex from the API– IvanS95
Nov 14 '18 at 14:22
Not really tried this, but maybe there's something you can do working with the
selectedIndex from the API– IvanS95
Nov 14 '18 at 14:22
add a comment |
2 Answers
2
active
oldest
votes
You could try using an *ngFor to keep the tabs dynamic
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let tab in tabList" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1'
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2'
}];
Then from there you can you can sort the this.tabList object however you want with your conditions
EDIT:
After a question in comments about *ngIf on the <mat-tab>'s, here is a revised answer with *ngIf statements
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<ng-template ngFor let-tab [ngForOf]="tabList">
<mat-tab *ngIf="tab.showTab || someHideFunction(tab)" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
</ng-template>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1',
showTab: true
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2',
showTab: false
}, {
label: 'Third Tab',
innerHtml: `<app-custom-component [input]="tempVariable"></app-custom-component>`,
tabId: 'tab3',
showTab: true
}];
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some*ngIfs on the<mat-tab>declaration and it's not possible to use*ngIfand*ngForon the same element. Any suggestions?
– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be yourtabListthat has all possible tabs, then your second one would be apopulatedTabListthat contains all the tabs you can show to the user. ThetabListwould be a reference and thepopulatedTabListwould be what you edit/manipulate/put into the*ngFor. OR possibly adding an<ng-template>as a work around. But other than that I would need to see more code.
– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
|
show 1 more comment
You can use ng-template for this like following.
<ng-template #content1>
<div>Content 1</div>
</ng-template>
<ng-template #content2>
<div>Content 2!</div>
</ng-template>
Then use in your tabs accordingly.
<mat-tab id="tab0" [label]="yourFirstLabel">
<div *ngIf="yourFlag; then content1 else content2"> </div>
</mat-tab>
<mat-tab id="tab1" [label]="yourSecondLabel">
<div *ngIf="yourFlag; then content2 else content1"> </div>
</mat-tab>
Note that you need to update your labels (yourFirstLabel and yourSecondLabel) too
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302061%2fchanging-the-order-of-angular-mat-tabs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could try using an *ngFor to keep the tabs dynamic
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let tab in tabList" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1'
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2'
}];
Then from there you can you can sort the this.tabList object however you want with your conditions
EDIT:
After a question in comments about *ngIf on the <mat-tab>'s, here is a revised answer with *ngIf statements
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<ng-template ngFor let-tab [ngForOf]="tabList">
<mat-tab *ngIf="tab.showTab || someHideFunction(tab)" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
</ng-template>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1',
showTab: true
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2',
showTab: false
}, {
label: 'Third Tab',
innerHtml: `<app-custom-component [input]="tempVariable"></app-custom-component>`,
tabId: 'tab3',
showTab: true
}];
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some*ngIfs on the<mat-tab>declaration and it's not possible to use*ngIfand*ngForon the same element. Any suggestions?
– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be yourtabListthat has all possible tabs, then your second one would be apopulatedTabListthat contains all the tabs you can show to the user. ThetabListwould be a reference and thepopulatedTabListwould be what you edit/manipulate/put into the*ngFor. OR possibly adding an<ng-template>as a work around. But other than that I would need to see more code.
– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
|
show 1 more comment
You could try using an *ngFor to keep the tabs dynamic
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let tab in tabList" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1'
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2'
}];
Then from there you can you can sort the this.tabList object however you want with your conditions
EDIT:
After a question in comments about *ngIf on the <mat-tab>'s, here is a revised answer with *ngIf statements
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<ng-template ngFor let-tab [ngForOf]="tabList">
<mat-tab *ngIf="tab.showTab || someHideFunction(tab)" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
</ng-template>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1',
showTab: true
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2',
showTab: false
}, {
label: 'Third Tab',
innerHtml: `<app-custom-component [input]="tempVariable"></app-custom-component>`,
tabId: 'tab3',
showTab: true
}];
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some*ngIfs on the<mat-tab>declaration and it's not possible to use*ngIfand*ngForon the same element. Any suggestions?
– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be yourtabListthat has all possible tabs, then your second one would be apopulatedTabListthat contains all the tabs you can show to the user. ThetabListwould be a reference and thepopulatedTabListwould be what you edit/manipulate/put into the*ngFor. OR possibly adding an<ng-template>as a work around. But other than that I would need to see more code.
– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
|
show 1 more comment
You could try using an *ngFor to keep the tabs dynamic
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let tab in tabList" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1'
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2'
}];
Then from there you can you can sort the this.tabList object however you want with your conditions
EDIT:
After a question in comments about *ngIf on the <mat-tab>'s, here is a revised answer with *ngIf statements
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<ng-template ngFor let-tab [ngForOf]="tabList">
<mat-tab *ngIf="tab.showTab || someHideFunction(tab)" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
</ng-template>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1',
showTab: true
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2',
showTab: false
}, {
label: 'Third Tab',
innerHtml: `<app-custom-component [input]="tempVariable"></app-custom-component>`,
tabId: 'tab3',
showTab: true
}];
You could try using an *ngFor to keep the tabs dynamic
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let tab in tabList" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1'
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2'
}];
Then from there you can you can sort the this.tabList object however you want with your conditions
EDIT:
After a question in comments about *ngIf on the <mat-tab>'s, here is a revised answer with *ngIf statements
html
<mat-tab-group #tabsGroup (selectedTabChange)="tabChanged($event)" (selectedIndexChange)="selectedIndexChange($event)" [(selectedIndex)]="selectedIndex">
<ng-template ngFor let-tab [ngForOf]="tabList">
<mat-tab *ngIf="tab.showTab || someHideFunction(tab)" id="{{tab.tabId}}" label="tab.label">
<div [innerHtml]="tab.innerHtml"></div>
</mat-tab>
</ng-template>
<mat-tab-group>
ts
tabList = [{
label: 'First Tab',
innerHtml: `<div>hello, World!</div>`,
tabId: 'tab1',
showTab: true
}, {
label: 'Second Tab',
innerHtml: `<div>I am a different Tab</div>`,
tabId: 'tab2',
showTab: false
}, {
label: 'Third Tab',
innerHtml: `<app-custom-component [input]="tempVariable"></app-custom-component>`,
tabId: 'tab3',
showTab: true
}];
edited Nov 15 '18 at 17:20
answered Nov 14 '18 at 14:31
rhavelkarhavelka
698219
698219
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some*ngIfs on the<mat-tab>declaration and it's not possible to use*ngIfand*ngForon the same element. Any suggestions?
– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be yourtabListthat has all possible tabs, then your second one would be apopulatedTabListthat contains all the tabs you can show to the user. ThetabListwould be a reference and thepopulatedTabListwould be what you edit/manipulate/put into the*ngFor. OR possibly adding an<ng-template>as a work around. But other than that I would need to see more code.
– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
|
show 1 more comment
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some*ngIfs on the<mat-tab>declaration and it's not possible to use*ngIfand*ngForon the same element. Any suggestions?
– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be yourtabListthat has all possible tabs, then your second one would be apopulatedTabListthat contains all the tabs you can show to the user. ThetabListwould be a reference and thepopulatedTabListwould be what you edit/manipulate/put into the*ngFor. OR possibly adding an<ng-template>as a work around. But other than that I would need to see more code.
– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
You can also do this with child component. And pass them an input.
– Swoox
Nov 14 '18 at 14:33
I tried to use it like this, but I need to put also some
*ngIfs on the <mat-tab> declaration and it's not possible to use *ngIf and *ngFor on the same element. Any suggestions?– decebal
Nov 15 '18 at 8:31
I tried to use it like this, but I need to put also some
*ngIfs on the <mat-tab> declaration and it's not possible to use *ngIf and *ngFor on the same element. Any suggestions?– decebal
Nov 15 '18 at 8:31
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be your
tabList that has all possible tabs, then your second one would be a populatedTabList that contains all the tabs you can show to the user. The tabList would be a reference and the populatedTabList would be what you edit/manipulate/put into the *ngFor. OR possibly adding an <ng-template> as a work around. But other than that I would need to see more code.– rhavelka
Nov 15 '18 at 17:08
@decebal If you provided more code I could update my answer to reflect what you need. But off the top of my head, I would say have 2 lists. the first list would be your
tabList that has all possible tabs, then your second one would be a populatedTabList that contains all the tabs you can show to the user. The tabList would be a reference and the populatedTabList would be what you edit/manipulate/put into the *ngFor. OR possibly adding an <ng-template> as a work around. But other than that I would need to see more code.– rhavelka
Nov 15 '18 at 17:08
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
I added an edit with what I think you want
– rhavelka
Nov 15 '18 at 17:20
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
@decebal did the update work for you?
– rhavelka
Nov 16 '18 at 17:07
|
show 1 more comment
You can use ng-template for this like following.
<ng-template #content1>
<div>Content 1</div>
</ng-template>
<ng-template #content2>
<div>Content 2!</div>
</ng-template>
Then use in your tabs accordingly.
<mat-tab id="tab0" [label]="yourFirstLabel">
<div *ngIf="yourFlag; then content1 else content2"> </div>
</mat-tab>
<mat-tab id="tab1" [label]="yourSecondLabel">
<div *ngIf="yourFlag; then content2 else content1"> </div>
</mat-tab>
Note that you need to update your labels (yourFirstLabel and yourSecondLabel) too
add a comment |
You can use ng-template for this like following.
<ng-template #content1>
<div>Content 1</div>
</ng-template>
<ng-template #content2>
<div>Content 2!</div>
</ng-template>
Then use in your tabs accordingly.
<mat-tab id="tab0" [label]="yourFirstLabel">
<div *ngIf="yourFlag; then content1 else content2"> </div>
</mat-tab>
<mat-tab id="tab1" [label]="yourSecondLabel">
<div *ngIf="yourFlag; then content2 else content1"> </div>
</mat-tab>
Note that you need to update your labels (yourFirstLabel and yourSecondLabel) too
add a comment |
You can use ng-template for this like following.
<ng-template #content1>
<div>Content 1</div>
</ng-template>
<ng-template #content2>
<div>Content 2!</div>
</ng-template>
Then use in your tabs accordingly.
<mat-tab id="tab0" [label]="yourFirstLabel">
<div *ngIf="yourFlag; then content1 else content2"> </div>
</mat-tab>
<mat-tab id="tab1" [label]="yourSecondLabel">
<div *ngIf="yourFlag; then content2 else content1"> </div>
</mat-tab>
Note that you need to update your labels (yourFirstLabel and yourSecondLabel) too
You can use ng-template for this like following.
<ng-template #content1>
<div>Content 1</div>
</ng-template>
<ng-template #content2>
<div>Content 2!</div>
</ng-template>
Then use in your tabs accordingly.
<mat-tab id="tab0" [label]="yourFirstLabel">
<div *ngIf="yourFlag; then content1 else content2"> </div>
</mat-tab>
<mat-tab id="tab1" [label]="yourSecondLabel">
<div *ngIf="yourFlag; then content2 else content1"> </div>
</mat-tab>
Note that you need to update your labels (yourFirstLabel and yourSecondLabel) too
answered Nov 14 '18 at 14:29
Yousef khanYousef khan
568411
568411
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302061%2fchanging-the-order-of-angular-mat-tabs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not really tried this, but maybe there's something you can do working with the
selectedIndexfrom the API– IvanS95
Nov 14 '18 at 14:22