2017-04-21 65 views
0

我一直在尋找幾個小時的答案,我想我需要添加一個單獨的問題。我有以下表和控制器:在AngularJS中更新沒有範圍的模型

<table class="table table-striped"> 
     <thead> 
     <tr> 
      <th>value</th> 
      <th>datapoint</th> 
     </tr> 
     </thead> 
     <tr ng-repeat="obj in cont.objs"> 
      <td>{{ obj.value }}</td> 
      <td>{{ obj.datapoint }}</td> 
     </tr> 
</table> 
<button>Next</button> 

objects.controller.js

(function() { 
    'use strict'; 

    angular 
     .module('app.objects') 
     .controller('ObjectsController', ObjectsController); 

    ObjectsController.$inject = ['objectsService', '$state', '$stateParams', '$uibModal', 'logger']; 

    function ObjectsController(objectsService, $state, $stateParams, $uibModal, logger) { 
     var cont = this; 

     activate().then(function successCallback(selectObjects) { 
      cont.objects = loadObjects(selectObjects._links.objects.href); 
     }); 
    } 

    function loadObjects(uri) { 
    ... 
     cont.objects = getObjects(uri) 
     return cont.objects; 
    } 
... 

我有一個按鈕「下一步」,按下時,需要通過獲取新的更新cont.objects通過調用具有原始uri +'/ 2'的loadObjects來從api繼承對象。

我想,也許

<button ng-click="cont.loadObjects(cont.objects.next.href)">Next</button> 

會的工作,但我得到一個錯誤說裝入對象是不確定的。有任何想法嗎?

回答

0

您沒有將該功能綁定到範圍。您需要將該函數添加到控制器中並進行綁定。

function ObjectsController(objectsService, $state, $stateParams, $uibModal, logger) { 
    var cont = this; 
    cont.loadObjects = loadObjects; 

    function loadObjects(uri) { 
    cont.objects = getObjects(uri) 
    return cont.objects; 
    } 

    activate().then(function successCallback(selectObjects) { 
    cont.objects = loadObjects(selectObjects._links.objects.href); 
    }); 
}