Я хочу предотвратить автоматическое выполнение компонентов при загрузке временной страницы. Я хочу выполнить компонент на основе нашего времени выбора.Как создать динамический динамический компонент 2?
Когда страница загружает компонент времени, выполняющий и добавляющий html-ответ на странице. Я не хочу его исполнять.
Проблема заключается в том, что «HeapMemoryComponent» выполняет и добавляет ответ html на странице во время загрузки страницы, прежде чем предпринимать какие-либо действия.
Я хочу, чтобы выполнить "HeapMemoryComponent" после того, как на основе выбора пункта
я говорил this code
routing.ts
import {ModuleWithProviders} from '@angular/core';
import {Router,RouterModule} from '@angular/router';
import {AppComponent} from './app.component';
import {HeapMemoryComponent} from './heap-memory/heap-memory.component'
const appRoutes:Routes = [
{
path: 'abc',
component: HeapMemoryComponent
}
];
export const routing:ModuleWithProviders = RouterModule.forRoot(appRoutes);
LeftPanelComponent.ts
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']);
}
});
}
}
После нажатия на «Да» Я выполняю, как следующий компонент bas по выбору элементов.
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() {}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import {HeapMemoryComponent} from './heap-memory/heap-memory.component'
@NgModule({
declarations: [
AppComponent,
LeftpanelComponent,
RightpanelComponent,
HeapMemoryComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule.forRoot(),
DndModule.forRoot(),
routing
],
providers: [LeftpanelService,.....],
bootstrap: [AppComponent],
entryComponents:[
ServersListDialogComponent
]
})
export class AppModule { }
Над HeapMemoryComponent есть HTML ответ и это выше компонент будет иметь службу. И у меня будет несколько компонентов, как указано выше.
Пожалуйста, дайте мне решение.
Вы можете использовать '' ngIf', ngSwitch' или 'ViewContainerRef.createComponent()' http://stackoverflow.com/questions/36325212/angular-2- dynamic-tabs-with-user-click-selected-components/36325468 # 36325468 –
@Gunter Zochbauer, где мне нужно добавить код? пожалуйста, помогите мне, я новичок в угловой. –
Извините, вопрос слишком длинный. У меня нет времени, чтобы понять, в чем проблема. –