简体   繁体   中英

ng-init not working with sails.get("/..")

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?

尝试一下

>>>> $sails.get('/getInfo/',{ id: id })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM