EmberJS – Named Arguments

  • Post author:
  • Post category:EmberJS
  • Post comments:1 Comment
named arguments

You can pass the named arguments along with the related value.

Syntax

export default Ember.Helper.helper(function([value],namedArgs) {
   //code here
});

Example

The example given below passes named arguments along with the related value to the helper. Create two helpers as namedarguments and namedarguments1. Open the namedarguments.js file, which is created under app/helpers/ and add the following code to it −

import Ember from 'ember';

export default Ember.Helper.helper(function([value], args) {
   let var1 = Math.floor(value * 100);
   let var2 = value % 100;
   let var3 = args.var3 === undefined ? '$' : args.var3;
   if (var2.toString().length === 1)
   return `${var3}${var1}`;
});

Open another helper file namedarguments1.js file and add the following code −

import Ember from 'ember';

export default Ember.Helper.helper(function(params, args) {
   document.write("Text is : " +args.option1+ ''+args.option2);
});

Open the index.hbs file and write the following code −

{{namedarguments1 option1 = "Welcome to" option2 = "Adglob"}}
{{outlet}}

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply