5 Replies Latest reply: Aug 25, 2014 3:08 PM by Shane Porter RSS

    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.