TheRunner565 TheRunner565 - 1 year ago 52
AngularJS Question

Updating model without scope in AngularJS

I have been searching for answers for several hours and I think I need to add a separate question. I have the following table and controller:

<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;
}
...


I have a button 'Next' and when pressed, needs to update cont.objects by fetching new cont.objects from the api by calling loadObjects with the original uri + '/2'.

I thought maybe

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


would work, but I get an error saying loadObjects is undefined. Any ideas?

Answer Source

Hope you had defined activate() function and to make this work use controller As with the controller definition and make sure you are clicking the button after the success of activate() function . https://toddmotto.com/digging-into-angulars-controller-as-syntax/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download