EasyUI Forum
April 18, 2024, 08:03:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to dynamically add tabs with layout for angular?  (Read 12681 times)
softboy99
Newbie
*
Posts: 43


View Profile Email
« on: January 15, 2018, 08:32:43 PM »

How to dynamically add tabs with layout for angular?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: January 16, 2018, 12:35:07 AM »

This is the example shows how to create tab panels dynamically.
Code:
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
template: `
<eui-tabs style="height:250px">
<eui-tab-panel *ngFor="let tab of tabs" [title]="tab.title">
<p>{{tab.content}}</p>
</eui-tab-panel>
</eui-tabs>
`
})
export class AppComponent {
tabs = [{
title: 'Tab1',
content: 'Content1'
},{
title: 'Tab2',
content: 'Content2'
},{
title: 'Tab3',
content: 'Content3'
}];
}
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #2 on: January 16, 2018, 01:33:49 AM »

Hi,
Thanks. Sorry for the confusion, your code is static,what i mean to dynamically add tabs and load content compent, which load data from remote server.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: January 16, 2018, 06:16:53 PM »

To add a new tab panel, just new a 'tabs' entry with 'content' property. This 'content' property value can be retrieved from your remote server. Please look at this example.
Code:
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
selector: 'app-root',
template: `
<button (click)="addTab()">add tab</button>
<eui-tabs [selectedIndex]="selectedIndex" style="height:250px">
<eui-tab-panel *ngFor="let tab of tabs" [title]="tab.title">
<div *ngIf="tab.content" [innerHTML]="tab.content"></div>
</eui-tab-panel>
</eui-tabs>
`
})
export class AppComponent {
selectedIndex = 0;

tabs:[any] = [{
title: 'Tab1',
content: 'Content1'
},{
title: 'Tab2',
content: 'Content2'
},{
title: 'Tab3',
content: 'Content3'
}];

constructor(private http: HttpClient, private sanitizer: DomSanitizer){}

addTab() {
this.http.get('...',{responseType:'text'}).subscribe(data => {
let content = this.sanitizer.bypassSecurityTrustHtml(data);
this.tabs.push({
title: 'New Tab',
content: content
});
setTimeout(() => this.selectedIndex = this.tabs.length-1);
});
}
}
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #4 on: January 16, 2018, 09:49:32 PM »

Hi,
Thanks for your help. In addition, can we dynamically load another angular component,which has it own UI design and data from remote server, to the newly added tab? Any sample code?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #5 on: January 17, 2018, 01:22:17 AM »

You can nest any components inside a panel component. Please look at this example:
https://www.jeasyui.com/demo-angular/main/index.php?plugin=FileButton&theme=material&dir=ltr&pitem=Select%20Files&sort=
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #6 on: January 18, 2018, 10:33:45 PM »

Hi,
In your sample, there is only one component. There is no component created and load dynamically. Are you sure the sample?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #7 on: January 19, 2018, 12:23:13 AM »

Please open https://angular.io/guide/dynamic-component-loader to learn how to add components dynamically.
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #8 on: February 01, 2018, 06:51:01 AM »

Hi,
Is there api method like addTab in ts code not the template way in your sample code? Just like Jquery EasyUI?
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #9 on: February 02, 2018, 12:02:01 AM »

Hi :
Could you please kindly give us a sample of this? Thanks a lot for your great help.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #10 on: February 02, 2018, 12:39:58 AM »

No dom operating methods are available. You should prevent from creating dom elements directly like jQuery.
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #11 on: February 02, 2018, 01:58:43 AM »

Hi,
Could you give us sample for dynamically add tab and load another angular component to the added tab? I searched the web.Most of them is static way.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!