Listening to events in Durandal -
i'm reviewing durandal documentation, , can't find concrete implementation of listening durandal events, e.g, router events.
can point me docs, or (if there no documentation on this) example?
in view model should listen activator events. link. check example durandal starter template. listening activate , candeactivate events:
define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) { //note: module exports object. //that means every module "requires" same object instance. //if wish able create multiple instances, instead export function. //see "welcome" module example of function export. return { displayname: 'flickr', images: ko.observablearray([]), activate: function () { //the router's activator calls function , waits complete before proceding if (this.images().length > 0) { return; } var = this; return http.jsonp('http://api.flickr.com/services/feeds/photos_public.gne', { tags: 'mount ranier', tagmode: 'any', format: 'json' }, 'jsoncallback').then(function(response) { that.images(response.items); }); }, select: function(item) { //the app model allows easy display of modal dialogs passing view model //views located convention, specify viewurl item.viewurl = 'views/detail'; app.showdialog(item); }, candeactivate: function () { //the router's activator calls function see if can leave screen return app.showmessage('are sure want leave page?', 'navigate', ['yes', 'no']); } }; });
Comments
Post a Comment