角度2:找不到模块:错误:无法解决 [英] Angular 2: Module not found: Error: Can't resolve

查看:61
本文介绍了角度2:找不到模块:错误:无法解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Angular-CLI创建的简单应用程序,我想将app.component.ts代码重构并移动到单独的组件文件中,并开始遇到讨厌的错误:

I have a simple app created with Angular-CLI, I wanted to refactor and move the app.component.ts code in separate component file and started to get a nasty error:

未找到模块:错误:无法在'./sb/sb.component.html'( 我的SBComponent).在

Module not found: Error: Can't resolve on './sb/sb.component.html' ( my SBComponent). Under the

这是我拥有的:

app.module:

app.module:

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 { }

app.component:

app.component:

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  {



}

任何帮助将不胜感激!

推荐答案

如果您的组件位于同一目录中,那么您还需要将templateUrl指向同一文件夹.这是您的操作方法:

If your component is inside the same directory, then you need to point your templateUrl to the same folder as well. Here is how you can do it:

@Component({
    selector: 'app-sb',
    templateUrl: './sb.component.html'
})

这篇关于角度2:找不到模块:错误:无法解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆