簡體   English   中英

角度內容不顯示

[英]Angular Content Not Showing Up

因此,我創建了一個新組件,將其導入並聲明到 AppModule 中,並為標簽使用了適當的選擇器名稱。 但不知何故內容沒有顯示,有什么問題?

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { HelloComponent } from "./hello/hello.component";

@NgModule({
  imports: [ BrowserModule ],
  declarations: [
    AppComponent,
    HelloComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {

}

https://plnkr.co/edit/JfBoe38MZqRlvTLB?preview

控制台錯誤 GET https://run.plnkr.co/preview/ckgj32p39001k3a6cujj3nr87/app.component.html 404

未處理的承諾拒絕:無法加載 app.component.html ; 區域: ; 任務: Promise.then ; 值:無法加載 app.component.html zone.js@0.6.25?main=browser:357

錯誤:未捕獲(承諾):無法加載 app.component.html

我無法在 plunker 上進行調試,所以我嘗試了 stackblitz。

我在根目錄的 hello 文件夾中創建了一個簡單的 hello 組件。

你好/hello.component.ts

import { Component, OnInit } from "@angular/core";

@Component({
  selector: "app-hello",
  templateUrl: "./hello.component.html",
  styleUrls: ["./hello.component.css"]
})
export class HelloComponent implements OnInit {
  constructor() {}

  ngOnInit() {}
}

在 app.module.ts 中添加了這個

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";

import { AppComponent } from "./app.component";
import { HelloComponent } from "./hello/hello.component";

@NgModule({
  imports: [BrowserModule, FormsModule],
  declarations: [AppComponent, HelloComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}

然后在 app.component.html 中添加 hello 組件

<p>
  Start editing to see some magic happen :)
</p>
<app-hello></app-hello>

它工作正常。 你可以這里查看工作演示

預覽 - 在此處輸入圖片說明

如果您有任何疑問,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM