-1

My HTML

ng-app and ng-controller are specified in markup earlier

<div class="statusEntry" ng-repeat="statusInput in statusInputs">
 <span class="userName"> a </span>                
 <span  class="statusMsg"> b </span>                
</div>

Controller

app.controller('globalCtrl', ['$scope', function($scope) {
//someWork
pubnub.subscribe({
channel: "statuses",
callback:
function (data) {

    splitData = data.split(';');
    prepData = '{'+splitData[0]+','+splitData[1]+'}';
    statusInputs.push(prepData);
}
});

When I push the data no new object appears.

Slytherin
  • 474
  • 3
  • 17
  • Are you assigning statusInputs to the controller scope? – Daniel Beck Mar 27 '14 at 18:37
  • Could the problem be that this function is called from within PubNub ? – Slytherin Mar 27 '14 at 18:42
  • Where is the `ng-init`? – Davin Tryon Mar 27 '14 at 18:43
  • i dont have ng-init in the markup anywhere, on ng-init the array is empty. – Slytherin Mar 27 '14 at 18:44
  • @DanielBeck Im afraid not, but i dont know how to check it. Sorry if this is stupid question but i am just starting with Angular and already getting stuck – Slytherin Mar 27 '14 at 18:48
  • what does `{{statusInputs|json}}` display? If it's not there, it is a problem getting your data nd you should close and reword your question since it has nothing to do with Angular and ng-repeat – Jason Goemaat Mar 27 '14 at 19:16
  • @JasonGoemaat Looks like you're right. Any hint about how should i ask the correct question ? Should i ask "how to call angular function from pubnub" ? – Slytherin Mar 27 '14 at 19:22
  • I've never used `pubnub` but I'm guessing it's a problem with that. Put `console.log` statements to make sure that's getting executed and your controller is getting loaded. Try the `pubnub.subscribe` on its own and put a `console.log` in the callback to see that you're getting the data. Check the `network` tab in chrome to see if any data is flowing. With that info you can narrow down what's not working. – Jason Goemaat Mar 28 '14 at 22:02

2 Answers2

1
  1. Your Controller has no name.

  2. You haven't declare an ng-app or ng-controller in your markup anywhere.

  3. data should be named $scope so Angular can appropriately inject the dependency.

  4. It doesn't look like either statusInputs or your function are part of the $scope therefore there's no way for your view to access them.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
0

Replace

statusInputs.push(prepData);

with

$scope.statusInputs.push(prepData);

This is how you enable your views to access them.

CoderSpinoza
  • 2,145
  • 23
  • 28