0
votes

In DurandalJS I've created an Activator in my ViewModel which will be bound against a Compose Binding in the View. Trivial example:

var ViewModel = function(){
    this.childView = activator.create();
    this.activate = function(whyIsThisUndefined){ console.error('Well?' + whyIsThisUndefined); }
}


<div data-bind="compose: { model : theModel, activationData: [1]}"></div>

What am I doing wrong? Why isn't Durandal passing the activation parameters?

1
Hey, PW, Kad, I actually just read that article. I'm aware of that syntax and found several references to it in my googling, but even using hard-coded values, nothing is being passed to my activate methods. Do you have a working example I could see? What version of Durandal are you using? (2.0.1 for me).Oliver Kane
2.0.1 in that sample. Can you change your activation data to activationData: { data: 'Hey!!!!' } and then console.log(whyIsThisUndefined) and see if there is a data property on that object?PW Kad
Regardless of what I place as the value of activationData, nothing gets passed into the activate function. Eg: if I were to call console.log(arguments) there would be none. There is no error. It behaves as if "activationData" isn't recognized, or was mispeled. Similar to how ttext would be bound. There's no matching binding so it's just silently ignored.Oliver Kane
I know Rainer has working examples of almost everything here - dfiddle.github.io/dFiddle-2.0/#extras - it's possible you could find one on activation that helps you debug, but my best guess is that your activate function may not be getting passed data because it is a singleton, but again, that is a guess.PW Kad

1 Answers

3
votes

When you use Singleton's for your view models, I don't think the parameters are passed to the activate function each subsequent time. Pass in your data as such -

activationData: { data: 'Hey!!!!' } 

And make sure you are creating activate onto the prototype and creating a new instance of the view model (or AMD module) each time.