VOOZH about

URL: https://www.geeksforgeeks.org/javascript/ember-js-historylocation-toggleproperty-method/

⇱ Ember.js HistoryLocation toggleProperty() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Ember.js HistoryLocation toggleProperty() Method

Last Updated : 28 Apr, 2025

Ember.js is a JavaScript framework for building web applications. It is based on the Model-View-Controller (MVC) pattern and is designed to make it easy to create complex feature-rich web applications. Ember.js provides a set of tools and conventions for building web applications that help to manage the complexity of a modern web application.

HistoryLocation is a class in Ember.js that provides a location implementation that uses the browser's history.pushState API to change the URL and keep the application state in sync with the URL. It is not directly related to toggleProperty() method.

The toggleProperty() method in HistoryLocation is used to toggle a boolean property on an object. It works by checking the current value of the property and then setting it to the opposite value (i.e. if it is true, it sets it to false and vice versa). The method is typically used to toggle the state of a component or object in the Ember.js application.

 

Syntax:

toggleProperty( keyName );

Parameters:

  •  keyName: It is the name of the property to toggle.

Return Value: The new property value.

Steps to install and run Ember.js:

Step 1: To run the following examples you will need to have an ember project with you. To create one, you will need to install ember-cli first. Write the below code in the terminal:

npm install ember-cli

Step 2: Now you can create the project by typing in the following piece of code:

ember new <project-name> --lang en

To start the server, type:

ember serve

Example 1: Type the following code to generate the route for this example:

app/controllers/toggleProperty1.js

app/templates/toggleProperty1.hbs

Output:

👁 Image
toggleProperty output1

Example 2: Type the following code to generate the route for this example:

ember generate route toggleProperty2

app/routes/toggleProperty2.js

app/controllers/toggleProperty2.js

app/templates/toggleProperty2.hbs

Comment