';模态';不是已知元素:在angular2中

';模态';不是已知元素:在angular2中,angular,typescript,Angular,Typescript,我尝试在angular2中使用model box,我知道如何将其与systemConfig.js一起使用,但现在在我的新项目中,我有webpack.js,我不确定如何使用它。 我的组件 import {Component,OnInit} from "@angular/core"; import {ModalModule} from "ng2-modal"; import { Http, Headers } from '@angular/http'; @Component({ sel

我尝试在angular2中使用model box,我知道如何将其与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;
                }
            })
    }
}
从“@angular/core”导入{Component,OnInit};
从“ng2模式”导入{ModalModule};
从'@angular/Http'导入{Http,Headers};
@组成部分({
选择器:“[tables basic]”,
模板:`
打开我的模态
模态头
你好,莫代尔!
关闭
`
})
导出类TablesBasic实现OnInit{
学生:任何;
构造函数(公共http:http){
}
恩戈尼尼特(){
这个。getstudents();
}
getstudents(){
var headers=新的headers();
headers.append('Content-Type','application/json')
this.http.get('http://localhost:3009/api/auth/getstudents“,{headers:headers})
.订阅(
结果=>{
if(result.json().error_code==0){
this.students=result.json().result;
}
否则{
this.students=result.json().result;
}
})
}
}
我的错误, 错误:模板分析错误: “模态”不是已知的元素: 1.如果“模态”是一个角度组件,则确认它是该模块的一部分。 2.如果“modal”是Web组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.SCHEMA”以抑制此消息。(" 打开我的模态 [错误->] 模态头
任何人都可以建议我帮助。

您需要在
AppModule
文件中导入
ModalModule
,并需要在
@NgModule中添加
ModalModule
。导入如下所示:

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

我在使用第三方组件“ng2-bs3-modal”时也有类似的错误 没有生成错误,但在加载页面时,它没有加载页面并显示
“正在加载…” 仅限留言

解决办法是 1.在app.module.ts中添加“从'ng2-bs3-modal/ng2-bs3-modal';'导入{Ng2Bs3ModalModule}” 2.在@NgModule部分下的imports部分添加“Ng2Bs3ModalModule”

这一变化解决了问题

你也可以参考
我也面临同样的问题。 按照下面提到的步骤来解决问题

.npm安装ng2模式


然后导入ModalModule到@ngModule

的imports:section中。您可能忘了将模态模块添加到根ngModule的导入中。模态模块的文档应该解释如何使用它。