【发布时间】:2017-06-04 09:32:02
【问题描述】:
我在页面的左侧面板上有 8 个图形图像。当我拖动这些图像并放在右侧面板上时,我正在显示 MD 对话框。在 md 对话框中,我在下拉菜单中显示列表。
我推荐了this code
从下拉列表中选择项目后,我单击 md 对话框的“是”按钮。
在此按钮上单击我想根据项目选择执行特定组件。例如,如果我选择“Heap Memory”,那么我想执行“HeapMemoryComponent”等。
路由.ts
import {ModuleWithProviders} from '@angular/core';
import {Routes,RouterModule} from '@angular/router';
import {AppComponent} from './app.component';
import {HeapMemoryComponent} from './aem-down-time-graph/aem-down-time-graph.component'
const appRoutes:Routes = [
{
path: 'abc',
component: HeapMemoryComponent
}
];
export const routing:ModuleWithProviders = RouterModule.forRoot(appRoutes);
左面板组件
import { Component, OnInit } from '@angular/core';
import {LeftpanelService} from "../leftpanel.service"
import {Leftpanel} from "../leftpanel";
import {MdDialog} from "@angular/material";
import {MdDialogRef} from "@angular/material";
import { Routes, RouterModule } from '@angular/router';
import {ServersListDialogComponent} from "../servers-list-dialog/servers-list-dialog.component";
@Component({
selector: 'app-leftpanel',
templateUrl: './leftpanel.component.html',
styleUrls: ['./leftpanel.component.css']
})
export class LeftpanelComponent implements OnInit {
dialogRef: MdDialogRef<ServersListDialogComponent>;
leftpanels:Leftpanel[];
receivedData:Array<any> = [];
constructor(
public dialog: MdDialog,private service:LeftpanelService,public router:Router
) { }
ngOnInit() {
this.service.getLeftpanels().subscribe(lst =>this.leftpanels=lst);
}
transferDataSuccess($event) {
this.receivedData.push($event.dragData);
this.openDialog();
}
openDialog() {
this.dialogRef = this.dialog.open(ServersListDialogComponent, {
disableClose: false
});
this.dialogRef.afterClosed().subscribe(result => {
console.log('result: ' + result);
this.dialogRef = null;
if(result.componentName == "HeapMemoryComponent"){
this.router.navigate(['HeapMemoryComponent']);
}
});
}
}
点击“是”后,我想根据项目选择执行以下组件。
@Component({
selector: 'app-mainpanel',
templateUrl: './heap-memory.component.html',
styleUrls: ['heap-memory.component.css']
})
export class HeapMemoryComponent implements OnInit {
constructor() {
console.log("HeapMemoryComponent object is created...");
}
ngOnInit() {
console.log("HeapMemoryComponent ....");
}
}
HeapMemoryComponent 上面有一些 html 响应,上面的这个组件将有服务。而且我会有多个像上面这样的组件。
我不知道如何像上面的特定组件那样执行? 请给我解决方案
【问题讨论】:
-
您的意思是导航到特定组件吗?
-
@echonax。是的,我想根据项目选择导航特定组件。
标签: angular angular2-services angular2-directives