我一直在寻找几个小时的答案,我想我需要添加一个单独的问题。我有下表和控制器:
<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;
}
...
我有一个按钮&#39; Next&#39;当按下时,需要通过使用原始uri +&#39; / 2&#39;调用loadObjects从api中获取新的cont.object来更新cont.object。
我想也许
<button ng-click="cont.loadObjects(cont.objects.next.href)">Next</button>
会工作,但我得到一个错误,说loadObjects是未定义的。有什么想法吗?
答案 0 :(得分: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);
});
}
答案 1 :(得分:0)
希望您已经定义了activate()函数并使其工作正常 controller与控制器定义一样,确保在activate()函数成功后单击按钮。 https://toddmotto.com/digging-into-angulars-controller-as-syntax/