ember.jsember-dataember-cliember-componentsember-controllers

how to bind Application controller property in another controller ember


i have search property in ApplicationController and its linked with input field of searching. i want to access search field of ApplicationController in ProjectController. it should be sync. i use following code but its not working.

/ app/controllers/projects/index.js (project Controller)

import Ember from 'ember';
export default Ember.Controller.extend({
    needs: ['application'],
    searchBinding: 'controllers.application.search'
});

/ app/controllers/application.js (Application Controller)

  import Ember from 'ember';
    export default Ember.Controller.extend({
      search: ''
    )}

application.hbs

{{input value = search}}


Solution

  • You can access any controller within controller by inject it.

    import Ember from 'ember';
    export default Ember.Controller.extend({
        applicationController: Ember.inject.controller('application'),
        searchProperty: Ember.computed.alias('applicationController.search'),
    )};
    

    Managing Dependences between Ember controllers