javascript - Update Knockout Observable string in refresh function -


the code in typescript , trying show current date time on page load , update date time on refresh click.

in .ts file string shows date time declared this.

   asofstring: knockoutobservable<string>; 

in constructor being set this,

 this.asofstring = ko.observable(new date().todatestring() + " " + new date().tolocaletimestring()); 

in html being bind this,

           <a class="small button" data-bind="click: updatesummary">refresh</a> 

in refresh button trying update this,

 this.asofstring(new date().todatestring() + " " + new date().tolocaletimestring()); //latest date time. 

it gives me error _this.asofstring not function.

please help.

code of view model this,

import ko = require('knockout');  class todayviewmodel {     asofstring: knockoutobservable<string>;      constructor() {         this.updatesummary();          this.asofstring = ko.observable(new date().todatestring() + " " + new date().tolocaletimestring());     }      updatesummary = () => { // function bound refresh button         //want update this.asofstring here     } }  export = todayviewmodel;   

this works fine me entire app. can't tell i'm doing differently describe, i'm including whole thing.

class todayvm {     asofstring: knockoutobservable<string>;      constructor() {         this.asofstring = ko.observable('');         this.updatesummary();     }     updatesummary = () => {         this.asofstring(new date().todatestring() + " " + new date().tolocaletimestring())     } }  window.onload = () => {     ko.applybindings(new todayvm()); }; 

html:

<!doctype html>  <html lang="en"> <head>     <meta charset="utf-8" />     <title>typescript html app</title>     <link rel="stylesheet" href="app.css" type="text/css" />     <script src="app.js"></script> </head> <body>     <h1>typescript html app</h1>      <div data-bind="text:asofstring"></div>     <button data-bind="click:updatesummary">update</button> </body> <script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script> </html> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -