Makeboundhelper Alternative In Ember 2.0
I've been injecting Google DFP ads in my blog-posts by using a bound helper so far. Since all Handlebars APIs have been removed in Ember 2.0 what can I use as of Ember 2.0 instead?
Solution 1:
You would use the Ember.Helper.helper syntax:
importEmberfrom'ember';
const { Helper: { helper }, run: { schedule }, $ } = Ember;
exportfunctionhelperName(params, hash) {
let parsedHtml = $('<div />').html(params[0])
// Push the ads after the divs have been renderedschedule('afterRender', function() {
googletag.cmd.push(function() { googletag.display('div-gpt-ad-111111111-0'); });
})
}
return parsedHtml.html();
}
exportdefaulthelper(helperName);
Params is an array of all the values that you pass to the helper in your template such as {{my-helper val1 val2 val3}}
params[0]
is val1
and so on, the hash is an object containing all the properties you set on the helper {{my-helper val1 val2 property1=myPropValue}}
and you would access it via hash.property1
.
Post a Comment for "Makeboundhelper Alternative In Ember 2.0"