Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

module.exports in Android Alloy not working - Uncaught TypeError

$
0
0

I have an app which all works fine in ios but not android and I'm struggling to understand why.

In Android I get a Message: Uncaught TypeError: Object function Controller() { error

and another error of

has no method 'allEvents'

If I remove the loadEvents function the app will load fine, I'm a little unsure what the error is but it sounds like it can't find the function in the module.exports.

So i have a file events.js

var moment = require('moment'), ui = require('ui'), Events = require('Events');
 
$.loading = Alloy.createController('loading');
$.events.add($.loading.getView());
$.loading.start();
 
function loadEvents() {
    var listEvents = [];
    Events.allEvents(5000, function(data) {
        if (data) {
            for (var i = 0; i < data.length; i++) {
                var event = data[i], row = new ui.EventRow(event);
                listEvents.push(row);
            }
            $.eventsTable.setData(listEvents);
            $.loading.stop();
            $.events.remove($.loading.getView());
        }
    });
}
 
//Listen for status update, and refresh.
function startRefresh() {
    Ti.API.info('Events refresh');
    $.events.add($.loading.getView());
    $.loading.start();
    loadEvents();
}
startRefresh();
and Events.js in my lib folder
var XHR = require('xhr');
var xhr = new XHR();
//Empty constructor (for now)
function Events() {
}
 
Events.allEvents = function(timeout, onSuccess) {
    Ti.API.info("allEvents function was called...");
    var url = 'https://myapi.com';
 
    var onSuccessCallback = function(e) {
        if (e.status == 'ok' || e.status == 'cache') {
            var data = JSON.parse(e.data);
            onSuccess(data, e.code);
            Ti.App.fireEvent('app:eventsLoaded');
        }
    }
    var onErrorCallback = function(e) {
        Ti.App.fireEvent('app:eventsLoaded');
        Ti.API.info(e.status);
    }
    var options = {
        ttl : 5,
    };
    xhr.get(url, onSuccessCallback, onErrorCallback, options);
}
 
module.exports = Events;

Viewing all articles
Browse latest Browse all 7655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>