gpt4 book ai didi

angular - 'modal' 不是已知元素 : in angular2

转载 作者:太空狗 更新时间:2023-10-29 18:21:03 25 4
gpt4 key购买 nike

我尝试在 angular2 中使用模型框,我知道如何将它与 systemConfig.js 一起使用,但现在在我的新项目中我有 webpack.js 但我不确定如何使用它。我的组件,

 import {Component,OnInit} from "@angular/core";
import {ModalModule} from "ng2-modal";
import { Http, Headers } from '@angular/http';

@Component({
selector: '[tables-basic]',
template: `
<div class="row">
<button (click)="myModal.open()">open my modal</button>
<modal #myModal>
<modal-header>
<h1>Modal header</h1>
</modal-header>
<modal-content>
Hello Modal!
</modal-content>
<modal-footer>
<button class="btn btn-primary" (click)="myModal.close()">close</button>
</modal-footer>
</modal>
</div>
`
})
export class TablesBasic implements OnInit {
students:any;
constructor(public http: Http) {


}
ngOnInit() {
this.getstudents();
}
getstudents() {
var headers = new Headers();
headers.append('Content-Type', 'application/json')
this.http.get('http://localhost:3009/api/auth/getstudents', { headers: headers })
.subscribe(
result => {
if (result.json().error_code == 0) {
this.students = result.json().result;
}
else {
this.students = result.json().result;
}
})
}
}

我的错误, 错误:模板解析错误: 'modal' 不是已知元素: 1. 如果“modal”是一个 Angular 组件,那么验证它是这个模块的一部分。 2. 如果“modal”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.schema”以抑制此消息。 (" 打开我的模态 [错误 ->]

模态标题

谁能建议我帮忙。

最佳答案

您需要在 AppModule 文件中导入 ModalModule 并且需要在 @NgModule.imports 中添加 ModalModule如下:

import {ModalModule} from "ng2-modal";
@NgModule({
imports: [
// ...
ModalModule
],
declarations: [
App,
TablesBasic
],
bootstrap: [
App
]
})
export class AppModule {
}

关于angular - 'modal' 不是已知元素 : in angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40303003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com