【问题标题】:App component doesn't render child component应用组件不呈现子组件
【发布时间】:2022-11-01 22:10:57
【问题描述】:

我的 app.component 没有呈现子组件模板,但是在网页上检查后我可以看到 customer-form.component 但它没有呈现。我已经为所有组件添加了我的文件。

app.component.html=

<h1>Customer services</h1> <app-customer-form></app-customer-form> 

app.module.ts=

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CustomDirectDirective } from './custom-direct.directive';
import { CustomerFormComponent } from './customer-form/customer-form.component';
import { DisplayCustomerComponent } from './display-customer/display-customer.component';

@NgModule({
  declarations: [
    AppComponent,
    CustomDirectDirective,
    CustomerFormComponent,
    DisplayCustomerComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

客户-form.component.html=

<h2>this is customer form</h2>

客户-form.component.ts=

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

@Component({
  selector: 'app-customer-form',
  templateUrl: './customer-form.component.html',
  styleUrls: ['./customer-form.component.css']
})
export class CustomerFormComponent implements OnInit {
  

  constructor(public customer: Customer) { }

  ngOnInit(): void {
    
  }


  customerForm(data: any){
    
  }

}

它在检查时显示子组件,但不在页面上呈现。

Inspect element Image

【问题讨论】:

    标签: angular


    【解决方案1】:

    使用 CSS 使孩子适合容器。我认为孩子的高度和宽度是 0*0

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2020-12-11
      • 2017-12-02
      • 2018-09-25
      • 1970-01-01
      相关资源
      最近更新 更多