Ember.js Ember.Templates.helpers debugger() Method
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of websites, including Square, Discourse, Groupon, Linked In, Live Nation, Twitch, and Chipotle.
The debugger() method is used to execute the debugger statement in the current template’s context.
Syntax:
{{ debugger }}
Parameters: It doesn’t take any argument.
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 server
Example 1: Type the following code to generate the route for this example:
ember generate route debugger1
app/routes/debugger1.js
Javascript
import Route from '@ember/routing/route' ; import EmberObject from '@ember/object' ; export default class WebsitesRoute extends Route { food = [ EmberObject.create({ food: 'apple' , isFruit: true , quant: 3, }), EmberObject.create({ food: 'Potato' , isFruit: false , quant: 4, }), EmberObject.create({ food: 'Banana' , isFruit: true , quant: 2, }), EmberObject.create({ food: 'Burgur' , isFruit: false , quant: 2, }), ]; temp; model() { return this .food; } setupController(controller, model) { super .setupController(controller, model); controller.set( 'food' , this .food); controller.set( 'temp' , this .temp); controller.set( 'food2' , this .food2); } } |
app/templates/debugger1.hbs
HTML
{{page-title "debugger"}} < h3 >List of Item in Buckets</ h3 > < table > < tr > < th > Food_Name </ th > < th >Bucket </ th > < th >Fruit </ th > </ tr > {{#each @model as |website|}} < tr > {{debugger}} < td >{{website.food}}</ td > < td >{{website.quant}}</ td > < td >{{website.isFruit}}</ td > </ tr > {{/each}} </ table > {{outlet}} |
Output:
Example 2: Type the following code to generate the route for this example:
ember generate route debugger2
app/routes/debugger2.js
Javascript
import Route from '@ember/routing/route' ; import EmberObject from '@ember/object' ; import { } from '@ember/array' ; export default class FruitsRoute extends Route { students = [ EmberObject.create({ name: 'Rahul' , Class: 11, marks: 75 }), EmberObject.create({ name: 'Sam' , Class: 12, marks: 59 }), EmberObject.create({ name: 'David' , Class: 11, marks: 67 }), EmberObject.create({ name: 'Druv' , Class: 12, marks: 44 }), EmberObject.create({ name: 'Mahan' , Class: 12, marks: 87 }), ]; model() { return this .students; } setupController(controller, model) { super .setupController(controller, model); controller.set( 'students' , this .students); } } |
app/templates/debugger2.hbs
HTML
{{page-title "debugger"}} < h3 >Students List: </ h3 > < table > < tr > < th >Name</ th > < th >Class</ th > < th >Marks</ th > </ tr > {{#each @model as |detail|}} < tr > < td >{{detail.name}}</ td > < td >{{detail.Class}}</ td > < td >{{detail.marks}}</ td > {{debugger}} </ tr > {{/each}} </ table > {{outlet}} |
Output:
Reference: https://api.emberjs.com/ember/4.4/classes/Ember.Templates.helpers/methods/debugger?anchor=debugger
Contact Us