kuskunko
kuskunko

Reputation: 330

How to a Durandal widget return values?

I have a Durandal widget in Hot Towel Template and I need to use some values from widget in external view. I tried this:

<div data-bind="widget: { kind: 'myWidget', items: projects, value: newValue }"></div>
<span data-bind="text: newValue"></span>

But newValue is empty. In controller.js I set settings.value successfully, but I think that settings is only used to work along to the widget, but I need to get some values from Durandal widget. Is it possible?

I am new in Durandal widget, please any help much appreciated!

Upvotes: 1

Views: 665

Answers (1)

jvrdelafuente
jvrdelafuente

Reputation: 2002

I had the same problem time ago. I solved this problem using the durandal events. You can find more information in the next url: http://durandaljs.com/documentation/Events/

Also in some cases I have use the url to send some information between a widget and a view, but it is for a very specific situation. When doing something in the widget implies to change the current view.

If you need more information about one of this solution, I can add some examples.

-----EDIT----

To throw an event in durandal you have to use the app module:

app.trigger("someEvent");

To catch this event, you have to do that:

app.on("someEvent", function () {
  //Do that you want
});

So, you can throw an event from the widget, and capture where you want.

Upvotes: 4

Related Questions