Angular 自定义标签不呈现和执行功能
Angular custom tag not rendering and executing function
我在 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
}
}
您在 Directive/Component 中的选择器是 nextbutton 而您将标签用作
<next-button></next-button>
将选择器更改为 next-button 或将标签更改为 nextbutton
我在 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
}
}
您在 Directive/Component 中的选择器是 nextbutton 而您将标签用作
<next-button></next-button>
将选择器更改为 next-button 或将标签更改为 nextbutton