Skip to content

Instantly share code, notes, and snippets.

@pswai
Last active February 6, 2017 01:15
Show Gist options
  • Save pswai/1e7e4e1206c980515f185c251a766922 to your computer and use it in GitHub Desktop.
Save pswai/1e7e4e1206c980515f185c251a766922 to your computer and use it in GitHub Desktop.
Ember.js #14697 (htmlSafe) sample use case
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
const foo = this.get('store').createRecord('foo', {
text: '<b>foo</b>'
});
this.set('foo', foo);
},
foo: null,
savedValue: '',
actions: {
saveValue() {
this.set('savedValue', Ember.copy(this.get('foo.safeText')));
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
text: attr('string'),
safeText: Ember.computed('text', function() {
return Ember.String.htmlSafe(this.get('text'));
})
});
<p>No htmlSafe: {{foo.text}}</p>
<p>htmlSafe: {{foo.safeText}}</p>
<p>Saved value: {{savedValue}}</p>
<button type="button" {{action 'saveValue'}}>Save</button>
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment