TheRunner565 TheRunner565 -3 years ago 82
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">
<tr ng-repeat="obj in cont.objs">
<td>{{ obj.value }}</td>
<td>{{ obj.datapoint }}</td>


(function() {
'use strict';

.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(">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 .

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