emberjs-essentials icon indicating copy to clipboard operation
emberjs-essentials copied to clipboard

Ember.ObjectController deprecated chapter5

Open zhisme opened this issue 9 years ago • 2 comments

Hello. Ember.ObjectController is now deprecated so how I can implement this features now?


import Ember from "ember";
export default Ember.ObjectController.extend({

formattedPrice: function(){
  returnthis.get('symbol') + "
  " +
  $.number(this.get('price'),2);
  }.property('symbol','price'),
formattedDimension: function(){
  return this.get('dimensions.width') + " x " +
  this.get('dimensions.height') + " x " +
  this.get('dimensions.length');
 }.property('dimensions.width','dimensions.height',
   'dimensions.length'),
shortDescription: function(){
  varshortDesc = this.get('description').substring(0, 25);
  returnshortDesc + "...";
  }.property('description')
});

Used this in the same controller app/controllers/products.js the following code, but no result was given. It's just raises errors. Looking forward to your answer.

zhisme avatar Mar 19 '16 11:03 zhisme

Well the computed properties are still valid on any ember obect

https://guides.emberjs.com/v2.4.0/object-model/computed-properties/
Person = Ember.Object.extend({
  // these will be supplied by `create`
  firstName: null,
  lastName: null,

  fullName: Ember.computed('firstName', 'lastName', function() {
    return `${this.get('firstName')} ${this.get('lastName')}`;
  })
});

var ironMan = Person.create({
  firstName: 'Tony',
  lastName:  'Stark'
});

ironMan.get('fullName'); // "Tony Stark"

see here. https://guides.emberjs.com/v2.4.0/object-model/computed-properties/

suchitpuri avatar Mar 19 '16 12:03 suchitpuri

@suchitpuri thanks for answer, I will try

zhisme avatar Mar 19 '16 14:03 zhisme