我有一个使用 Angular-CLI 创建的简单应用程序,我想重构 app.component.ts 代码并将其移动到单独的组件文件中,并开始出现严重错误:
找不到模块:错误:无法解析“./sb/sb.component.html”(我的 SBComponent)。在下面
这就是我所拥有的:
应用程序模块:
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 { SBComponent } from './sb/sb.component'
@NgModule({
declarations: [
AppComponent, SBComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
应用程序组件:
import { Component } from '@angular/core';
import { NgModule,ElementRef, ViewChild, AfterViewInit} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
新组件:
import { Component, OnInit } from '@angular/core';
import { NgModule,ElementRef, ViewChild, AfterViewInit, AfterContentInit} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'app-sb',
templateUrl: './sb/sb.component.html'
})
export class SBComponent {
}
任何帮助将不胜感激!