Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
Hi,
some thoughts:
Regards
Stefan
Hi Shane - I have informed a few members who may be able to help you.
Mike
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?
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.
Hi,
some thoughts:
Regards
Stefan
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.