我在共享模块上创建了一个子组件,以显示警报消息。但是,当我将其注入到父组件中时,我在控制台中看到了该标签,但在组件内部却没有看到引导卡。
alertmessage.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'alertmessage',
templateUrl: './alert-message.component.html',
styleUrls: ['./alert-message.component.scss']
})
export class AlertMessageComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
alertmessage.component.html:
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
shared.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { NgxBootstrapModule } from './modules/ngx-bootstrap.module';
import { BeginsWithPipe } from './pipes/begins-with.pipe';
import { ShortUrlPipe } from './pipes/short-url.pipe';
import { AlertMessageComponent } from './components/alert-message/alert-message.component';
@NgModule({
declarations: [AlertMessageComponent],
imports: [
CommonModule,
NgxBootstrapModule,
TranslateModule
],
exports: [
CommonModule,
NgxBootstrapModule,
TranslateModule,
AlertMessageComponent
],
providers: []
})
export class SharedModule { }
这是我的文件夹组成:
Core
Shared
Components
alert-message
.ts
.html
.css
Pipes
shared.module.ts
Public
Private
admin
admin
qr-code-management
.ts
.html
.css
create
.ts
.html
.css
update
.ts
.html
.css
upload-file
admin.module.ts
private.module.ts
admin.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { ZXingScannerModule } from '@zxing/ngx-scanner';
import { NgxKjuaModule } from 'ngx-kjua';
import { SharedModule } from 'src/app/shared/shared.module';
...
@NgModule({
declarations: [...],
imports: [
CommonModule,
SharedModule,
FormsModule, ReactiveFormsModule,
CKEditorModule,
ZXingScannerModule,
NgxKjuaModule
],
exports: [
FormsModule, ReactiveFormsModule,
CKEditorModule,
ZXingScannerModule,
NgxKjuaModule
]
})
export class AdminModule { }
private.module.ts
import { NgModule } from '@angular/core';
import { PrivateRoutingModule } from './private-routing.module';
import { SharedModule } from '../shared/shared.module';
import { AdminModule } from './admin/admin.module';
@NgModule({
declarations: [],
imports: [
SharedModule,
PrivateRoutingModule,
AdminModule
]
})
export class PrivateModule { }
例如在我的update.component.html
中<h1 class="card-header blue">QR CODE MANAGEMENT - UPDATE</h1>
<alertmessage></alertmessage>
然后我在控制台中看到它,在这里我们可以看到组件中的标记,但里面没有任何内容。
答案 0 :(得分:0)
检查您的实际文件名和您在模板url中使用的文件名,我认为它们是不同的。实际文件名和模板url路径中的文件名应匹配