Hello guys. I am still new using ionic and this is probably an easy to fix problem but here it goes.
For my app ive been having a few problems i cant seem to figure out why.
I’m trying to make some divs with the ng-repeat, and its been working great with dummy data in my controller.
but now when i want to get my data from my database, using json and $http its not working as its suposed. shows the ‘wrong’ unless i go re-enter the view.
i can see from the output that it just takes a bit time to get the data from the database should i then just set a timer for the Situation.getSituations() or is there a smarter way?.
also i’ve tried using callback at the update part, so that when i run my Situations.getSituations(), then it updates first and then returns the array, but from the output inside the service it looks perfectly, but the output in my controller is still wrong. and the data is not shown.
controller.js:
Situation.update();
$scope.$on('$ionicView.enter', function (e) {
$scope.situations = Situation.getSituations();
console.log($scope.situations);
});
services.js:
.factory('Situation', function ($http) {
var situations = ["wrong"];
var update = function () {
var req = {
method: 'GET',
url: urlGET + "type=situations&userId=3",
headers: {
'Content-Type': "application/x-www-form-urlencoded"
},
data: "type=students"
}
$http(req).success(function (response) {
situations = response.situations;
console.log("updated! " + situations);
}).error(function () {
console.log('Der er sket kritisk fejl!, kontakt Actura');
});
}
return {
update: update,
getSituations: function () {
console.log("getSituations: " + situations)
return situations;
}
}
})
console output:
Ionic Core: init
ionic.io.bundle.min.js:2 Ionic Core: searching for cordova.js
ionic.io.bundle.min.js:2 Ionic Core: attempting to mock plugins
services.js:25 getSituations: wrong
controllers.js:97 ["wrong"]
ionic.io.bundle.min.js:2 Ionic Push: register
services.js:16 updated! [object Object]
ionic.io.bundle.min.js:2 Ionic Push (dev): registered with development push service
ionic.io.bundle.min.js:2 Ionic Push: (debug) device token registered: <PushToken ['DEV-b4bb631f-7954-4c7a-9640-136cb662a216']>
app.js:30 Device token: DEV-b4bb631f-7954-4c7a-9640-136cb662a216
ionic.io.bundle.min.js:2 Ionic Push (dev): watching for new notifications