I am developing a mobile application built in Wakanda Digital App Factory 1.0.3 using Ionic and AngularJS with a 4D backend database.
I have two different 4D methods available through 4D-Mobile via two separate 4D tables that are accessed via two different Angular controllers:
.controller('homeCtrl', function($scope, $wakanda) {
$wakanda.init('servers').then(function(ds) {
ds.servers.www4DMionicHomeOverview().$promise.then(function(event) {
$json = event.result;
$scope.overview = $json.servers;
$scope.healthCheck = $json.healthCheck;
}, function(err) {
debugger
console.log(err);
});
}, function(err) {
debugger
console.log(err);
});
})
.controller('errorLogCtrl', function($scope, $wakanda) {
$wakanda.init('server_log').then(function(ds) {
ds.server_log.www4DMionicErrorLog().$promise.then(function(event) {
$json = event.result;
$scope.errors = $json;
}, function(e) {
debugger
console.log(e);
});
}, function(e) {
debugger
console.log(e);
});
})
I am noticing a strange issue calling these 4D methods in that the first one will work but the second one will fail, regardless of which one i call first. That is, if i call ds.server_log.www4DMionicErrorLog()
first it works but then subsequent calls to ds.servers.www4DMionicHomeOverview()
fail until i refresh the browser.
The opposite is also true in that if i call ds.servers.www4DMionicHomeOverview()
first then it works but subsequent calls to ds.server_log.www4DMionicErrorLog()
fail.
The error i get for the second method is:
ionic.bundle.js:25642 TypeError: Cannot read property 'www4DMionicHomeOverview' of undefined
or
ionic.bundle.js:25642 TypeError: Cannot read property 'www4DMionicErrorLog' of undefined
Depending on which of the two methods I call first.
I am curious if this may be related to how i am calling $wakanda.init
from each controller. The documentation does not say it is bad to do this.
Would it be better to setup an Angular service and resolve $wakanda
in the service?
Replace
$wakanda.init('servers').then(function(ds) {...
by
$wakanda.init().then(function(ds) {...
And do the same for all in your controllers.
In your case, I recommend you to use $wakanda.init()