未调用角组件

问题描述 投票:1回答:2

我刚刚开始了有角度的项目。我创建了只有两个打印内容的新组件universal-table.component,但似乎无法调用此组件。当我转到http://localhost:4200/model时,也没有在浏览器中加载HTML,也没有填充浏览器日志,但是我可以在Firefox的“调试”标签中看到UniversalTableComponent_Host.ngfactory.js

Component:

import { Component, OnInit } from '@angular/core';
import {UniversalTable} from "./universal-table.model";

@Component({
  selector: 'app-universal-table',
  templateUrl: './universal-table.component.html',
  styleUrls: ['./universal-table.component.css']
})
export class UniversalTableComponent implements OnInit {
  private model: UniversalTable;

  // public universalTable: Field = new Field();

  constructor() {
    console.log("1");
  }

  ngOnInit() {
    console.log("2");
  }
}

路由器:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { UniversalTableComponent } from './universal-table/universal-table.component';


const routes: Routes = [
  {path: 'model', component: UniversalTableComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
angular angular-router
2个回答
0
投票

在app.component.html中,您必须添加:

<app-universal-table></app-universal-table>

这是调用根元素。


0
投票

应在[[app.component.html中放入

<router-outlet></router-outlet>

将在此处渲染您的组件。

© www.soinside.com 2019 - 2024. All rights reserved.