0

i am new in the AngularJS programming.So I call getDevice() scope function in my html and I seem to get in infinite loop.Console log:

angular.js:14800 Error: [$rootScope:infdig] http://errors.angularjs.org/1.6.9/$rootScope/infdig?p0=10&p1=%5B%5D
    at angular.js:88
    at m.$digest (angular.js:18418)
    at m.$apply (angular.js:18649)
    at l (angular.js:12627)
    at t (angular.js:12871)
    at XMLHttpRequest.A.onerror (angular.js:12799)

Code: App.js

var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope, $location, $http)
{
    $scope.getDevice = function(deviceId)
    {
        $http.get('http://localhost:8080/client/' + deviceId + '/receive/device')
        .then(function (response)
        {
            $scope.jsondata = response.data;
        })
        console.log("working");
    };

});

html

<body>
        <div ng-app="myApp" ng-controller="myController"> 
        {{getDevice("elsysDev")}}
        </div>
</body>

So what am I doing wrong?

3
  • Call function in your controller side just print jsondata to html side Commented May 6, 2018 at 12:49
  • Doesn't solve the problem Commented May 6, 2018 at 13:23
  • What is the error? Commented May 6, 2018 at 13:26

1 Answer 1

1

If you really wanted to call the method in the view use ng-init

Note: ng-init is fired only once

<body>
     <div ng-app="myApp" ng-controller="myController" ng-init="getDevice('elsysDev')"> 
     </div>
</body>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.