【问题标题】:ionic angular, child component wont display离子角度,子组件不会显示
【发布时间】:2021-07-12 03:27:31
【问题描述】:

我想要的是在 view-store-list.component 中渲染 delete.component。我不明白为什么它不会显示。据我所知,我所做的一切都是正确的。 我已经在我的模块中添加了子组件(delete.component),我有一段时间遇到这个问题,我就是想不通。你们能不能给我一些启示。

//rating.module 从'@angular/core'导入{ NgModule }; .....

@NgModule({
  declarations: [
    ViewStoreListComponent,
    DeleteComponent
  ],
  imports: [
    CommonModule,
    RatingRoutingModule,
    IonicModule,
    ReactiveFormsModule,
    FormsModule
  ]
})

导出类 RatingModule { }

//rating-routing.module

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ViewAddRatingComponent } from './views/view-add-rating/view-add-rating.component';
import { ViewStoreListComponent } from './views/view-store-list/view-store-list.component';


const routes: Routes = [
  {path : '', redirectTo: 'store-list', pathMatch: 'full'},
  {path: 'store-list', component: ViewStoreListComponent}
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class RatingRoutingModule { }

//view-store-list.html

<app-delete></app-delete>    <---- this wont display
<p>Heelo</p>                 <---- this would display

//delete.component.html

<div>
  <h1>DELETE COMPONENT</h1>
</div>

//delete.component.ts

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

@Component({
  selector: 'app-delete',
  templateUrl: './delete.component.html',
  styleUrls: ['./delete.component.scss'],
})
export class DeleteComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    console.log('FROM DELETE COMPONENT');
    
  }

}

【问题讨论】:

  • 添加您的 deleteComponent 代码,并在控制台中添加您看到的消息(如果有)
  • @Moshezauros,我已经更新了我的帖子,控制台也没有错误
  • 你在 app.module.ts 文件中声明了 DeleteComponent 吗?
  • 这对我来说是正确的,确保所有文件都已保存,然后尝试停止 ng serve 进程并重新启动它
  • 我不认为,我需要在我的 app.module 中声明删除组件,因为我只是要在我的评级模块中使用它,是的,我已经尝试停止它并再次运行它。问题依然存在

标签: angular ionic-framework routes


【解决方案1】:

导出删除组件模块:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { DeleteRoutingModule } from './delete-routing.module';
import { DeleteComponent } from './delete.component';


@NgModule({
  declarations: [DeleteComponent],
  imports: [
    CommonModule,
    DeleteRoutingModule,
  ],
  exports:[DeleteComponent]
})
export class DeleteComponentModule { }

rating.module 中导入此模块,而不是组件:

@NgModule({
  declarations: [
    ViewStoreListComponent,
  ],
  imports: [
    CommonModule,
    RatingRoutingModule,
    IonicModule,
    ReactiveFormsModule,
    FormsModule,
    DeleteComponentModule //import here
  ]
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2020-09-14
    • 2016-10-05
    • 2022-07-09
    相关资源
    最近更新 更多