Listview Converter Application Resources error


#1

Hi folks,

I’m trying to add a converter to a listview, and I’m following the documentation shown here: https://docs.nativescript.org/core-concepts/data-binding#example-7-adding-converters-in-the-application-module-resources

But when I run the application (on Android), I get the following error:

TypeError: Cannot set property ‘dateFormat’ of undefined File: "file:///data/data/org.nativescript.[myapplicationname]/files/app/views/mylist/mylist.js’

The line in question that it points to is the last one in this block:

var application = require("application");
var moment = require("moment");

var dateFormat = function(value) {
     return moment(value).format();
};
application.resources["dateFormat"] = dateFormat;

What am I missing, here? Any ideas?


#2

The application module changed.

Change this line:

application.resources["dateFormat"] = dateFormat;

to:

var appResources = application.getResources();
appResources.dateFormat = dateFormat;

#3

That did the trick, thanks!