【问题标题】:Uncaught Error: Template parse errors: 'app-my-profile' is not a known element:未捕获的错误:模板解析错误:“app-my-profile”不是已知元素:
【发布时间】:2018-12-03 20:07:25
【问题描述】:

我收到此错误:未捕获错误:模板解析错误:'app-my-profile' 不是已知元素,当我创建我的配置文件服务时

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { TabsModule } from 'ngx-bootstrap/tabs';

import { AppComponent } from './app.component';
import { LayoutService } from './core/services/layout.service';
import { MyprofileService } from './core/services/myprofile.service';
import { TopNavComponent } from './top-nav/top-nav.component';


@NgModule({
  declarations: [
    AppComponent,
    TopNavComponent
  ],
  imports: [
    BrowserModule,
    TabsModule.forRoot()
  ],
  providers: [LayoutService,MyprofileService],
  bootstrap: [AppComponent]
})
export class AppModule { }

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class MyprofileService {

  constructor() { }
}

【问题讨论】:

  • 您在哪个模块中创建了app-my-profile?您是否正确申报和出口?如果是,请确保您也导入该模块。

标签: angular


【解决方案1】:

听起来错误更多地与组件有关,而不是与您的服务有关。 就像拥有一个选择器为“app-my-profile”的组件(默认为 MyProfileComponent)。 由于这个组件没有包含在你的模块的声明数组中,所以他是未知的。

【讨论】:

    【解决方案2】:

    我很确定它缺少一个名为 app-my-profile 的组件,如上所述。

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 1970-01-01
      • 2021-03-25
      • 2018-05-24
      • 1970-01-01
      • 2018-01-24
      • 2020-03-21
      • 1970-01-01
      • 2020-04-19
      相关资源
      最近更新 更多