【发布时间】:2020-02-14 06:13:30
【问题描述】:
我在 html 中有一个自定义标签。在我的 next.component.ts 文件中,
@Component({
selector: 'nextbutton',
template: ` <button (click) = "nextfunc()">Next</button> `
})
export class NextComponent{
nextfunc() {
==>>我的 app.component.html 文件
<div>
<!--other tags-->
<next-button></next-button>
</div>
我无法呈现按钮并访问 nextfunc()
===>>我的 app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { AppComponent } from './app.component';
import { NextComponent } from './next.component';
@NgModule({
declarations: [
AppComponent,
NextComponent
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
export class AppModule { }
===>>我的 next.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'nextbutton',
template: ` <button (click) = "nextfunc()">Next</button> `
})
export class NextComponent{
nextfunc() {
//do something
}
}
【问题讨论】:
-
将选择器更改为
nextbutton to next-button -
成功了。谢谢。也许本地主机渲染很慢
标签: html angular typescript angular-components custom-tag