Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I am creating to switch on and off, but when i want to create a seperate function to toggle on and off. CLass is complaining that it expects a constructor unexpected token. How do i fix this issue?

What I have tried:

TypeScript
<pre lang="TypeScript">
// @ts-ignore
import { Component, onInit} from '@angular/core';

@Component({
  selector: 'toggle-button',
  template: `<button (click)="toggleState()">
        {{switched == true ? "ON" : "OFF"}}
  </button >`
})

export class ToggleButton implements onInit {
  // code goes here
  onInit() {

  }
  buttonState:boolean = false;

  function toggleState() { // unexpected token
    this.buttonState != this.buttonState;
  }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900