These are chat archives for canjs/canjs

4th
Jun 2015
Ilya Fadeev
@ilyavf
Jun 04 2015 02:13
hey guys, how can i define a computed property in a child component and setup a reference to it in its parent component?
Ilya Fadeev
@ilyavf
Jun 04 2015 02:22
var ChildVM = can.Map.extend({
  define: {
    myComputed: {
        get: function(){ return 'foo';}
    }
  }
});
can.Component.extend({
    tag: 'my-child',
    viewmodel: ChildVM
});
can.Component.extend({
    tag: 'my-parent',
    template: can.stache('<my-child myComputed="{getComputed}"></my-child>')
    viewmodel: {
        getComputed: null
    }
});
Chris Gomez
@akagomez
Jun 04 2015 03:37
I was wrong earlier. It’s computeA.computeInstance.value.
dylanrtt
@dylanrtt
Jun 04 2015 14:05
@ilyavf you can access the parent scope from the child to set properties like in this example:
http://jsbin.com/zoginopiwu/2/edit?html,js,console,output
but there might be a better approach to your problem if you could provide more info