R
R
run1822018-05-14 14:30:05
Angular
run182, 2018-05-14 14:30:05

How to display data through controller in AngularJS?

Here is the code from the controller

angular.module('erp7App')
  .controller('ClientsBrowserCtrl', function ($scope, api) {
    api.clients.allCompany("", function($scope, response) {		
    console.log(response.data);
    $scope.clientsCompany = response.data;
  });	
});

Error when running application in console:
TypeError: Cannot set property 'clientsCompany' of null

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Demian Smith, 2018-05-14
@search

Most likely you have an error in calling api.clients.allCompany.
Judging by the code, this function passes some data to the first argument of the callback, but the fact that this first argument is $scope is very unlikely.
Try to replace

api.clients.allCompany("", function($scope, response) {		
    console.log(response.data);
    $scope.clientsCompany = response.data;
});

on the
api.clients.allCompany("", function(_, response) {		
    console.log(response.data);
    $scope.clientsCompany = response.data;
});

This should help. But I recommend to figure out what exactly api.clients.allCompany passes to the callback.

D
Dmitry Eremin, 2018-05-14
@EreminD

and outputs response.data to the console?
There is what?
and if
$scope.clientsCompany = JSON.parse(response.data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question