html - 角度自定义标签不呈现和执行功能
问题描述
我在 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
}
}
解决方案
当您使用标签时,您的指令/组件中的选择器是下一个按钮
<next-button></next-button>
将您的选择器更改为下一个按钮或将标签更改为下一个按钮
推荐阅读
- python - 如何在同一个 HTML 页面上显示来自两个不同模型的数据
- ubuntu - x86 NASM 程序集中的阶乘函数出错
- python - 如何将数据发送到 EventHub 设置 PartitionId 而不是 PartitionKey (Python)
- javascript - Bootstrap 3轮播与asp net mvc中的动态源
- asp.net-core - 为什么在 ASP.NET Core 2.2 中以自动 400 响应发送 traceid
- ios - 在详细标题栏中,显示“Y 的图片 X”
- jquery - jQuery - 如果条件被忽略
- loops - 我正在尝试创建多个循环,但如果一个循环返回 null 它不会运行循环的其余部分。我该如何解决这个问题?
- mysql - 如何通过 ssh 在 bash stdout 中查看 mysql 状态消息?
- selenium - Selenium ChromeDriver 身份验证(使用 C#)