Questions tagged [knockout-components]

Components are a powerful, clean way of organizing your UI code into self-contained, reusable chunks. Components have been made available in 3.2.0.

Components are a powerful, clean way of organizing your UI code into self-contained, reusable chunks. They:

  • can represent individual controls/widgets, or entire sections of your application
  • contain their own view, and usually (but optionally) their own viewmodel
  • can either be preloaded, or loaded asynchronously (on demand) via AMD or other module systems
  • can receive parameters, and optionally write back changes to them or invoke callbacks
  • can be composed together (nested) or inherited from other components
  • can easily be packaged for reuse across projects
  • let you define your own conventions/logic for configuration and loading

This pattern is beneficial for large applications, because it simplifies development through clear organization and encapsulation, and helps to improve runtime performance by incrementally loading your application code and templates as needed.

Content referenced from Knockout.js under Components and Custom Elements - Overview.

82 questions
26
votes
5 answers

Does afterRender work with Knockout components?

afterRender works with template bindings, but after converting my templates to components, there does not seem to be any way to use afterRender. I have tried looking for an example of a component that uses afterRender, but cannot find anything.
Eric Kolotyluk
  • 1,958
  • 2
  • 21
  • 30
10
votes
3 answers

Knockout 3.2 components with named templates?

I'm trying to use the new components system in knockout 3.2.0. There isn't much documentation at the moment, but this does work. ko.components.register('price-input', { template: 'price-input' }) However the template binding allows…
InternalFX
  • 1,475
  • 12
  • 14
9
votes
1 answer

Knockout components communication

I have a web app that I want to convert to and SPA using ko components. I wonder how to do a kind of inter component communication. For example I want a "notification" component in which every single component can send notifications. I managed to…
8
votes
3 answers

KnockoutJS afterRender callback when all nested Components have been rendered?

I have a hierarchy of nested KnockoutJS Components using 3.2.0. It's working very well but I'm looking to execute some code once my entire hierarchy of components has been loaded and rendered. It's a rough equivalent of afterRender(), needed for the…
Rich Taylor
  • 106
  • 1
  • 5
7
votes
2 answers

Getting knockout.js custom component content

I am trying to create a custom component in knockout.js. HTML TEXT NEEDED Javascript ko.components.register('demo-widget', { template: '
New Text
' }); ko.applyBindings(); The component loads fine and…
Whesley Barnard
  • 309
  • 1
  • 10
7
votes
1 answer

Are components really faster compared to templates?

I decided to compare speed of components with ko 3.2 versus other template engines by adding components test in the following jsperf: http://jsperf.com/knockout-template-engines/19 The results are really puzzling me, since I see components to be 98%…
arva
  • 2,384
  • 1
  • 17
  • 14
6
votes
1 answer

Knockoutjs: Invoking function of parent component from child component

Problem: I'm trying to build a dashboard of widgets. Each widget will have a delete button on its header. When clicked on this button, corresponding widget have to disappear. How I designed: I have two knockout components. my-widget-list: VO will…
Thaha
  • 303
  • 3
  • 7
6
votes
1 answer

How to access custom element in a Knockout component?

Take a look at this scenario : ko.components.register('hello', { viewModel: function() { }, template: "

hello wrold

" }); If I use the generated html result will be:

hello world

But what…
amin
  • 3,672
  • 5
  • 33
  • 61
5
votes
1 answer

Is it possible to have nested knockout components in javascript

I want something like this: Is it possible to achieve this with the help of knockout components?
s3e3
  • 111
  • 1
  • 2
  • 8
5
votes
3 answers

Replace container element when using Knockout component

Is there a way to configure a Knockout component to replace the container element instead of nesting its content inside the container element? For example, if I have a custom component registered as my-custom-element with the following…
5
votes
1 answer

Call component function upon initialization in Knockout

With a normal view model I can call a function after initialization outside of it's context like so: var ViewModel = function () { this.Foo = function () { alert("bar"); }; }; var vm = new…
kspearrin
  • 10,238
  • 9
  • 53
  • 82
5
votes
1 answer

Knockout 3.2 component data context

I am using Knockout 3.2 and the new component system. I am trying to have components that include sub-components. Home Page (component - with HomePageViewModel) NewsFeed1 (component with HomePageViewModel.NewsFeedViewModel1) NewsFeed2…
4
votes
1 answer

WHY does it initialize this Knockout.js component in random order?

I am beyond confused... I am creating a list using Knockout.js components, templates, and custom elements. For some reason, the steps I create in my Viewmodel are being initialized in random order within the custom element definition! And it is…
4
votes
2 answers

Precompiling web components

I'm using the web component implementation in knockout.js in a project of mine in order to abstract UI components that I reuse throughout my app. One of those components is an About popup which contains a bunch of info on my app. Abstracting this…
fredrikekelund
  • 2,007
  • 2
  • 21
  • 33
4
votes
1 answer

Update observable from the custom components in knockout 3.2

I am trying to use custom components from knockout 3.2 and update the observable from within the component. Here is an example of my custom component: ko.components.register('voting', { viewModel: function(params) { var self =…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
1
2 3 4 5 6