javascript - Selection box model with typescript and knockout -


i new typescript , convert following knockout+js knockout+typescript. knockout+js working, still failing make work typescript....

view:

<select data-bind="options: choices, value: selectedchoice"></select> 

model:

var mymodel = {     choices: ["blue", "white", "black", "yellow"],     selectedchoice: ko.observable("yellow")  };  mymodel.selectedchoice.subscribe(function(newvalue) {    alert("the new value " + newvalue);  });   ko.applybindings(mymodel); 

typescript:

import basevm = require("./basevm");  class mymodel extends basevm {   choices = ko.observablearray(["one", "two", "three"]);    //here selectedchoice subscribe in typescript...  }  export = mymodel; 

in typescript within class you'll need put subscription code inside of constructor function. can use "this" access property want subscribe to.

class mymodel extends basevm {     choices = ko.observablearray(["one", "two", "three"]);     selectedchoice = ko.observable("yellow");      constructor() {         this.selectedchoice.subscribe(function (newvalue) {             alert("the new value " + newvalue);         });     } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -