DEV Community

Gcobani Mkontwana
Gcobani Mkontwana

Posted on

switching toggle button on and off using template

Hi team

I need some help with my logic below, basically i am answering this instruction below using angular js to create switch toggle button in Angular.

//instructions for the task.

We provided some simple Angular template code. Your goal is to modify the component so that you can properly toggle the button to switch between an ON state and an OFF state. When the button is on and it is clicked, it turns off and the text within it changes from ON to OFF and vice versa.

// code solution but its not showing any UI to switch on and off.
// @ts-ignore
`import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-area',
template: `

ON



`,
styles: []
})

export class MainAppComponent implements OnInit {
// code goes here
ngOnInit() {

}
}`

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (6)

 
gcizman profile image
Gcobani Mkontwana

@nlxdodge dont worry man got it figured it out, its working that was then while busy researching and been stuck then

 
gcizman profile image
Gcobani Mkontwana • Edited

@nlxdodge when im using a function complaining that it expects a constructor, how do i get rid of this error..?

Collapse
 
gcizman profile image
Gcobani Mkontwana

I believe my variablename will be toggle-button i guess, so the function must use it below the class and remove onInit method?. Please share full logic i dont want to miss steps

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay