Next" /> Next" /> Next"/>

Angular custom tag not rendering and executing function

1.4k Views Asked by At

I have a custom tag in html. In my next.component.ts file I have,

@Component({
  selector: 'nextbutton',
  template: ` <button (click) = "nextfunc()">Next</button> `
})

export class NextComponent{

  nextfunc() {

==>>my app.component.html file

<div>
<!--other tags-->
<next-button></next-button>

</div>

I am not able to render the button and access the nextfunc()

===>>My 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 { }

===>>my next.component.ts

    import { Component } from '@angular/core';

@Component({
  selector: 'nextbutton',
  template: ` <button (click) = "nextfunc()">Next</button> `
})

export class NextComponent{

  nextfunc() {
     //do something
  }
}
1

There are 1 best solutions below

1
Mustafa Kunwa On BEST ANSWER

Your Selector in Directive/Component is nextbutton while you are using tag as

 <next-button></next-button>

Either change your Selector to next-button or change tag to nextbutton