$component

19 views
Skip to first unread message

Noirabys

unread,
May 5, 2015, 10:18:15 AM5/5/15
to knock...@googlegroups.com
hi,

i thought that $component should be defined within a component template, is this a bug or do i missunderstand the concept?
the result is an empty Objekt: {}

i've tried it with ko version 3.3.0..


<my-component params="title: title"></my-component>

<script>
  
  function ViewModel(data){
    var self = this;
    self.title = ko.observable(data.title);
  }
  
  model = new ViewModel({ title: 'my title:'});
  
  function MyComponent(data){
    self.title = ko.observable(ko.unwrap(data.title));
  }
  
  ko.components.register('my-component', {
    template: '<h1 data-bind=\'text: title() \'></h1>  <div data-bind=\'text:ko.toJSON($component)\'></div>',
    viewModel: MyComponent
  });
   
  ko.applyBindings(model);
  
</script>


best regards,
  noirabys
Reply all
Reply to author
Forward
0 new messages