1

I am trying to use ng-init to initialize values for each item in my ng-repeat. Each ng-repeat iteration calls a method which then does a sails.get call to get info from the db about the specific item, which should show the data in my view. Is there some sort of problem using sails.get with a ng-repeat? Like a timing issue of some sort?

I have tested the sails.get and it works correctly

I have also tested the ng-init and it is definitely called.

Part of code:

$scope.setupMainInfo = function(id){
     $sails.get('/getInfo',{ id: id })
     .then(function onSuccess(response){

          $scope.main_info_holder.labels = response.info;
          return $scope.main_info_holder;

View uses it:

..ng-init='info_holder = setupMaininfo(x)'..

 <td>
    info:{{info_holder.labels}} 
 </td>

If I output data to console to test:

id:20
id:21

then only the data from db comes in

JWR {body: Array[2], headers: Object, statusCode: 200, data: Array[2], status: 200…}
JWR {body: Array[2], headers: Object, statusCode: 200, data: Array[2], status: 200…}

Really seems to be a timing issue?

cfl
  • 999
  • 1
  • 14
  • 34

1 Answers1

1

Try it

>>>> $sails.get('/getInfo/',{ id: id })
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
iman mohadesi
  • 109
  • 1
  • 8
  • Unfortunately adding / didn't help. But thank you for answer though. Any other ideas? :) – cfl Nov 12 '15 at 07:43
  • Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. It's also recommended that you don't post an answer if it's just a guess. A good answer will have a plausible reason for why it could solve the OP's issue. – Drenmi Nov 12 '15 at 09:34