javascript - AngularJS TypeError: undefined is not a function (Onsen UI) -
why code giving me error? first 2 iterations working, 3rd , subsequent ones give me error:
typeerror: undefined not function @ %home%/test/onsenui/lib/onsen/js/angular/angular.js:13566:28 @ completeoutstandingrequest (%home%/test/onsenui/lib/onsen/js/angular/angular.js:4109:10) @ %home%/test/onsenui/lib/onsen/js/angular/angular.js:4416:7
app.js
angular.module('app', ['onsen']); angular.module('app').controller('appcontroller', function($scope, $http, $timeout) { $scope.messages = {}; $scope.lastmsg = 0; $scope.setnewchatmessages = function(messages, lastmsg) { $scope.messages = messages;// visualize new messages $scope.lastmsg = lastmsg; homecoming true; } $scope.getnewchatmessages = function() { //if($scope.checkconnection()){ try{ $http.post('http://nexus.italiangamingempire.net/app/api.php', {action : 'getmsg', lastmsg : $scope.lastmsg}) .success(function (data, status, headers, config) { if(data.status==true){ if(data.messages.length>0){ //navigator.notification.beep(data.messages.length); console.log('you received '+data.messages.length+' new chat messages'); $scope.setnewchatmessages(data.messages, data.lastmsg); } } }) .error(function (data, status, headers, config) { alert('errors while retrieving new chat messages : '+data+' :: '+status); }); }catch(e){ console.log(e); } //} }; $scope.interval = function() { var cancelrefresh = $timeout(function func() { $scope.getnewchatmessages(); var cancelrefresh = $timeout($scope.interval(), 10000); },10000); }; $scope.getnewchatmessages(); $scope.interval(); });
index.html
(the controller set correctly):
<ons-list-item class="item" ng-repeat="message in messages"> <ons-row> <ons-col width="60px"> <div class="item-thum"></div> </ons-col> <ons-col> <header> <span class="item-title">{{message.user}}</span> <span class="item-label">{{message.date}}</span> </header> <p class="item-desc">{{message.text}}</p> </ons-col> </ons-row> </ons-list-item>
server response on first iteration:
{"status":true,"messages":[{"user":"test1","date":"01\/11\/2014","text":""}]},"lastmsg":1}
server response on other iterations:
{"status":false}
just change
var cancelrefresh = $timeout($scope.interval(), 10000);
to:
var cancelrefresh = $timeout($scope.interval, 10000);
javascript json angularjs scope onsen-ui
No comments:
Post a Comment