javascriptember.jshandlebars.jsember-componentsember-controllers

ember must call super method from component error


i just extending my ember component with my custom mixins class but unfortunately my log said an error

    Assertion Failed: You must call `this._super(...arguments);` when overriding `init` on a framework object. Please update <cahyowhy-mini-blog@component:post-item::ember395> to call `this._super(...arguments);` from `init`.
Error

but in my component(post-item) i've been declared my init method

import Ember from 'ember';
import BaseController from '../controllers/base-controller';
import Likepost from '../models/likepost';

export default Ember.Component.extend(BaseController, {
  posts: "",
  applyLayout(){
    Ember.$(document).ready(function () {
      let $grid = Ember.$('#post-container').imagesLoaded(function () {
        $grid.masonry({
          itemSelector: '.post-item',
          percentPosition: true,
          columnWidth: '.post-item',
        });
      });
    });
  },
  init(){
    this._super(...arguments);
  },
..... more code

and this is my basecontroller class

import Ember from 'ember';

export default Ember.Mixin.create({
  init(){
    //this._super(...arguments); //nek ra dipanggil neng component post item ra keno :(
    let afterRenderExist = this.afterRender !== undefined && typeof this.afterRender === "function";
    if (this.applicationRoute.documentReady && afterRenderExist) {
      Ember.run.schedule('afterRender', this, function () {
        this.afterRender();
      });
    } else if (afterRenderExist) {
      this.applicationRoute.on('onDocumentReady', this, function () {
        this.afterRender();
      });
    }
  },

but when i try to uncomment this syntax this._super(...arguments); in my base controller. the error is gone...

can anyone solve this :( ...


Solution

  • Idea is you need to call init which is defined in Ember.Component if you don't then you will get an assertion error.

    Ember.Component
       basecontroller (this._super is referring to Ember.Component)
          post-item (this._super is referring to basecontroller)   
    

    Simply to reach parent class which is Ember.Component. we need to this._super in all the places. Always calling this._super(...arguments) for init method is Good Practice.