Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Not applicable

Sense - AngularJS - $scope not populating correctly?

Hi everyone,

I have an extension, and in my template, I have the following code:

<button ng-click="getApps()">Get apps</button>

<div ng-repeat="a in allApps" style="clear:left">

  {{a.qTitle}}

</div>

In the extension's javascript code, I have the following code fragment:

controller: ['$scope', 'testService',

                function($scope, testService) {

                    $scope.getApps = function() {

                        testService.getApps().then(function(reply) {

                            $scope.allApps = reply;

                        });

                    };

     // rest of the code...

The testService code has the following definition for getApps():

getApps: function() {

                    var deferred = q.defer();

                    c.getAppList(function(reply) {

                        deferred.resolve(reply);

                    });

                    return deferred.promise;

                },

-----

When I click the 'Get Apps' button in my view, everything works as expected - I see a list of apps (their qTitle) in the view... GREAT!

However, and this has been driving me crazy, I cannot get the code to work when the app starts up... I want to see it when the extension runs for the first time... I can get it when I click the button, but I need it there 'straight away' (I know it's an async call, that's why that's in quotes).  I don't see any errors (in the dev tools), but I don't get anything back either.

Any help would be much appreciated...

THANKS!

Shane.

1 Solution

Accepted Solutions
Employee
Employee

Re: Sense - AngularJS - $scope not populating correctly?

Hi,

some thoughts:

  • try wrapping it in a $timeout ... sometimes this helps to find out if something hasen't been loaded properly (fast enough at the beginning); if this is the case, double-check your dependencies ...

Regards

Stefan

5 Replies
Employee
Employee

Re: Sense - AngularJS - $scope not populating correctly?

Hi Shane - I have informed a few members who may be able to help you.

Mike

Regards,
Mike Tarallo
Qlik
bmz
Valued Contributor

Re: Sense - AngularJS - $scope not populating correctly?

Hi Shane,

If I understand your question, I think you might just be able to just run the function in your JS as a sort of init.  So you could simply do $scope.getApps()...

Or create an init function to run when the page loads, and put the same function in there.

$scope.init = function(){

  //do whatever you need to do to get things rolling

$scope.getApps()

}

Does that make sense?

Not applicable

Re: Sense - AngularJS - $scope not populating correctly?

That's what I thought too.  Seems like a very logical thing to do

However, it doesn't seem to work at all.  The data isn't returned.  I can write code (let's say a console.log(...) call, and that works, but when I call the promise returning function, the scope isn't updated.

Employee
Employee

Re: Sense - AngularJS - $scope not populating correctly?

Hi,

some thoughts:

  • try wrapping it in a $timeout ... sometimes this helps to find out if something hasen't been loaded properly (fast enough at the beginning); if this is the case, double-check your dependencies ...

Regards

Stefan

Not applicable

Re: Sense - AngularJS - $scope not populating correctly?

Hi Stefan,

that was it! I wrapped the code in a $timeout as you suggested, and I now get something!

I was under the impression, however, that requirejs ensured that script (dependencies) were loaded before things were returned. 

Thanks again!

Shane.

Community Browser