1

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?

Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
Tim Penner
  • 3,551
  • 21
  • 36
  • Found these comments in the Wakanda source "Init method to execute once on your application (that will retrieve the WAF catalog, a description of your db)" and "After the init part done, you can access to the datastore via this singleton method" $wakandaResult.getDatastore = function() {. So assuming you can only init once, the documentation must be showing 2 examples of how to do it, not one example in the same app – garethb Apr 22 '16 at 00:45
  • @Tim: i dont know wakanda, but if your using ui-router i suggest that you resolve your $wakanda.init('xxx') in each sate, then in your controller you inject the result etc. let us know about the result, PS: do not forget to use the debugger :) – Marwen Trabelsi Apr 22 '16 at 01:28

2 Answers2

2

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()

  • Thanks! This seems to work, indicating it is OK to call `$wakanda.init` from multiple different controllers. However, would it be better to call `$wkanda.init` once from the LoginController and then utilize `var ds = $wakanda.getDataStore();` from the other controllers? If so, how can `var ds = $wakanda.getDataStore();` be used with a promise? – Tim Penner Apr 22 '16 at 16:09
1

My project uses 1.3.7 AngularJS

In an attempt to be more efficient, I reduce the number of calls to

$wakanda.init().then(function oninit(ds) {
                            $rootScope.ds = $wakanda.$ds;

Future calls use $rootScope.ds.

However each of my Services has it's own call to $wakanda.init();

        userCredentials: function(login,password,validate) {
        var deferred = $q.defer();

        $wakanda.init().then(function oninit(ds) {
            ds.User.userCredentials(login,password,validate, {
                onSuccess: function(data) {
                    deferred.resolve(data);
                },
                onError: function(err) {
                    deferred.reject(err.message);
                }
            });
        }); //$wakanda.init()

        return deferred.promise;
    },

I found that within the UI controllers multiple calls to $wakanda.init() would fail.

David Ringsmuth
  • 325
  • 1
  • 12