点击“在新标签页中打开”时,当前页面应在新标签页中打开。
我尝试过的操作:要在新标签页中打开当前页面,我在app-sidebar.component.ts中添加了“ routerLink:this.selectedOption.routerLink”
thirdOptions = [
{
name: 'Open in new tab',
icon: 'data-management',
routerLink: this.selectedOption.routerLink
}
];
app-sidebar.component.ts
import { AuthService } from 'projects/login/src/app/shared-services/auth.service';
import { Component, Inject } from '@angular/core';
import { Observable } from 'rxjs';
@Component({
selector: 'app-sidebar-root',
templateUrl: './app-sidebar.component.html',
styleUrls: ['./app-sidebar.component.scss']
})
export class AppSidebarComponent {
userInfo$: Observable<any>;
selectedOption = {
name: 'Dashboard',
icon: 'dashboard',
routerLink: '/dashboard'
};
mainOptions = [
{ name: 'Search', icon: 'search', routerLink: '/search' },
{ name: 'Dashboard', icon: 'dashboard', routerLink: '/dashboard' },
{ name: 'Budgeting', icon: 'budgeting', routerLink: '/budgeting' },
{ name: 'Invoicing', icon: 'invoicing', routerLink: '/invoicing' },
{ name: 'Reports', icon: 'reports', routerLink: '/reports' }
];
thirdOptions = [
{
name: 'Open in new tab',
icon: 'data-management',
routerLink: this.selectedOption.routerLink
}
];
public collapsed = false;
constructor(@Inject(AuthService) private authSevice: AuthService) {
if (window.localStorage.getItem('sidebar-is-collpased')) {
this.collapsed = JSON.parse(
window.localStorage.getItem('sidebar-is-collpased')
);
}
this.userInfo$ = this.authSevice.userInfo$;
}
public selectOption(option) {
this.selectedOption = option;
console.log(this.selectedOption.routerLink);
}
public collapsSidebar() {
...
}
}
app-sidebar.component.html
<div class="af-sidebar" [class.collapsed]="collapsed">
<div class="af-sidebar--header" (click)="collapsSidebar()">
<div class="af-sidebar--header--toggle-btn"></div>
</div>
<div class="af-sidebar--user">
<div class="af-sidebar--user--info">
</div>
</div>
<div class="af-sidebar--main-options">
<ng-container *ngFor="let option of mainOptions">
<sidebar-option
[option]="option"
routerLink="{{ option.routerLink }}"
(click)="selectOption(option)"
[selected]="option.name == selectedOption.name"
[collapsed]="collapsed"
></sidebar-option>
</ng-container>
</div>
<div class="af-sidebar--third-options">
<ng-container *ngFor="let option of thirdOptions">
<sidebar-option
[option]="option"
routerLink="{{ option.routerLink }}"
(click)="selectOption(option)"
[selected]="option.name == selectedOption.name"
[collapsed]="collapsed"
></sidebar-option>
</ng-container>
</div>
</div>
当我单击“在新选项卡中打开”时,它默认为/ dashboard(这是默认的selectedOption,不会在新选项卡中打开。
正确的行为应该是:当我单击“在新选项卡中打开”时,当前页面应在新选项卡中打开。例如,如果我当前在“报告”页面上,然后单击“在新选项卡中打开”,则“报告”页面应在新选项卡中打开
答案 0 :(得分:1)
this.externalWindow = window.open('', '', 'width=600,height=400,left=200,top=200');
或使用此
openGoogle() {
var google = window.open('http://www.google.com', "_blank");
var timer = setInterval(function() {
if(wingoogleclosed) {
clearInterval(timer);
alert('closed !!!');
}
}, 2000);
}
答案 1 :(得分:1)
您可以使用HTML标签来实现
<a href="" target="_blank"> Open in new tab </a>