Have you tried the promise/ then API's
If not, check @https://docs.angularjs.org/api/ng/service/$q

On Mon, Oct 20, 2014 at 8:35 AM, Hugo Vermaak <[email protected]> wrote:

> Hi all,
>
> I have the following in my HTML markup:
>
> <div class="row" ng-app ng-controller="clientController">
>     <div class="col-md-4">
>         <div class="well">
>             <div class="input-prepend">
>                 <label for="search-box" class="add-on">
>                     <i class="icon-search"></i>
>                 </label>
>                 <input id="client-search-box" class="form-control"
> type="text" placeholder="Search" ng-model="search.name">
>              </div>
>             <a class="btn btn-default" mdl-link="/client/"><i
> class="icon-plus"></i>Add a Client</a>
>         </div>
>     </div>
>     <div class="col-md-8">
>         <div class="well" id="client-list">
>             Clients<ul>
>                 <li ng-repeat="client in clients | filter:search |
> orderBy:name">
>                     <a href='/clients/{{client.id}}' title="{{client.name}}"
> class='resource-link'>{{client.name}} has {{ client.isActive }} </a>
>                 </li>
>             </ul>
>         </div>
>     </div>
> </div>
>
> and the following in my JavaScript:
>
> <script type="text/javascript">
>
>         function clientController($scope, $http) {
>             $http.get('/api/client.json').then(function (res) {
>                 var clients = res.data.result.client
>                 $.each(clients, function (clientKey, clientVal) {
>                     $http.get('/api/client/' + clientVal.id +
> '/reads.json', function (readData) {
>                         var reads = readData.result.client.reads;
>                         if (reads.read.length > 0) {
>                             var activeReads = 0;
>                             $.each(reads.read, function (readKey, readVal)
> {
>                                 if (readVal.islive == "True" &&
> readVal.isrunning == "True") {
>                                     activeReads++;
>                                 }
>                             });
>                             if (activeReads > 0) {
>                                 clientVal["isActive"] = true;
>                                 clientVal["activeReads"] = activeReads;
>                             } else {
>                                 clientVal["isActive"] = false;
>                                 clientVal["activeReads"] = activeReads;
>                             }
>                             clients.push(clientVal);
>                         }
>                     });
>                 });
>
>                 $scope.clients = clients;
>                 console.log($scope.clients); // I can see the isActive and
> activeReads here
>             });
>         }
> </script>
>
> My problem is that I cannot access the "isActive" and "activeReads" in the
> template, I am assuming that it has not loaded in yet, the question is how
> can I make it wait till the whole shebang has run before using it in my
> template?
> I hope all this makes sense.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Rishi Tandon*
Pearson Learning Technology Group

Mobile: (310) 926-9032

Pearson
Always Learning
Learn more at www.pearson.com

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to