Set parent controller property from child controller

Jordan

I have a flyers route that has a template called flyers.hbs

<div class="button-wrap">
    <button {{action 'back'}}>Go Back</button>
    {{#if isPrintable}}
        <button {{action 'print'}} class="float-right">Print Flyer</button>
    {{/if}}
</div>

{{outlet}}

In this flyers route I have view and new. New should only show the back button and view should show the back button and the print button. So in the view controller I specified a property like so.

import Ember from 'ember';

export default Ember.Controller.extend({
    isPrintable: true,
});

But obviously the parent controller for flyers does not see that property when I navigate to the view route so my print button is not showing.

What is the proper way to do this?

artych

As I understand you'd like to have {{isPrintable}} in flyers template with value dependent of active child route. Maybe this will work for you.

//flyers controller
import Ember from 'ember';

export default Ember.Controller.extend({
   isPrintable: true,
});

//child route
import Ember from 'ember';
export default Ember.Route.extend({

  parentController: Ember.computed( function() {
    return this.controllerFor('flyers');
  }),

  setupController: function(controller, model) {
    this._super(controller, model);
    this.get('parentController').set('isPrintable', false);
  },

  deactivate: function() {
    this.get('parentController').set('isPrintable', true);
  }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Child controller not inheriting from parent controller

From Java

AngularJS access parent scope from child controller

From Dev

Controller from Parent Layout is not access by child views

From Dev

Getting form state from child to parent controller

From Dev

Rails update child from parent controller

From Dev

EmberJS - how to access parent controller from within child controller?

From Java

How to access the child view controller from parent view controller in swift?

From Dev

How to access parent member controller from child controller

From Dev

Calling parent controller's method from a child controller

From Dev

Call a parent controller method from child modal controller (ui bootstrap)

From Dev

Calling parent controller's method from a child controller

From Dev

Access property of a directive from parent controller

From Dev

Pass property from Modal View Controller to Parent

From Dev

AngularJS - Access a parent controller from child -> child directive with the controllerAs notation

From Dev

Cannot set Parent property from child class

From Dev

iOS - How to set imageview of a parent view controller through child container?

From Dev

How do I present a view controller from UISearchViewController embedded in a child view controller of a parent view controller?

From Dev

How to update parent controller variables in child controller

From Dev

Override instance variable of parent controller in child controller

From Dev

Sorting Parent and Child in Grails Controller

From Dev

Acessing parent controller in child controllers

From Dev

Is there a way for a child controller to inherit a service "like" instance from its parent?

From Dev

Passing object from parent controller to isolated scope child directive

From Dev

Swift sending data from child view to parent view controller

From Dev

Parent id could not be accessed from child controller create action

From Dev

How do I save my child records from the parent controller?

From Dev

How to pass data from child to parent view controller? in swift

From Dev

JavaFX access parent Controller class from FXML child

From Dev

How to access child directives scope from parent controller

Related Related

  1. 1

    Child controller not inheriting from parent controller

  2. 2

    AngularJS access parent scope from child controller

  3. 3

    Controller from Parent Layout is not access by child views

  4. 4

    Getting form state from child to parent controller

  5. 5

    Rails update child from parent controller

  6. 6

    EmberJS - how to access parent controller from within child controller?

  7. 7

    How to access the child view controller from parent view controller in swift?

  8. 8

    How to access parent member controller from child controller

  9. 9

    Calling parent controller's method from a child controller

  10. 10

    Call a parent controller method from child modal controller (ui bootstrap)

  11. 11

    Calling parent controller's method from a child controller

  12. 12

    Access property of a directive from parent controller

  13. 13

    Pass property from Modal View Controller to Parent

  14. 14

    AngularJS - Access a parent controller from child -> child directive with the controllerAs notation

  15. 15

    Cannot set Parent property from child class

  16. 16

    iOS - How to set imageview of a parent view controller through child container?

  17. 17

    How do I present a view controller from UISearchViewController embedded in a child view controller of a parent view controller?

  18. 18

    How to update parent controller variables in child controller

  19. 19

    Override instance variable of parent controller in child controller

  20. 20

    Sorting Parent and Child in Grails Controller

  21. 21

    Acessing parent controller in child controllers

  22. 22

    Is there a way for a child controller to inherit a service "like" instance from its parent?

  23. 23

    Passing object from parent controller to isolated scope child directive

  24. 24

    Swift sending data from child view to parent view controller

  25. 25

    Parent id could not be accessed from child controller create action

  26. 26

    How do I save my child records from the parent controller?

  27. 27

    How to pass data from child to parent view controller? in swift

  28. 28

    JavaFX access parent Controller class from FXML child

  29. 29

    How to access child directives scope from parent controller

HotTag

Archive