I have recently started using knockoutJs with TypeScript viewmodels and WebPack to bundle it all together.
Previously, without modules and webpack, I could write something like this:
<p data-bind="text: moment().format('L')">
However, now I am encountering an error: Message: moment is not defined
If I use moment within the viewmodel (e.g. by assigning it to a variable), it works just fine.
Here is my viewmodel.ts file:
import * as ko from 'knockout';
import * as moment from 'moment';
class TestViewModel {
test = moment().format('L');
}
ko.applyBindings(new TestViewModel(), document.getElementById('mainbinding'));
And in my view (cshtml partial page):
<pre data-bind="text: test"></pre> <!-- this works -->
<pre data-bind="text:moment().format('L')"></pre> <!-- this does not work-->
Can someone please help me identify what I might be missing?