Skip to main content
edit
Source Link
Pankaj Parkar
  • 136.3k
  • 23
  • 241
  • 307

You shouldn't be call the getLogs() function on document.ready angular ng-app will run first and ask for the module and will throw and module error.

So the solution would be create a angular module when page gets loaded.

<script type="text/javascript">

    var app = angular.module("Log", []);
    app.controller('MiscController', function ($scope, $http) {
        $http.post("/misc/getlogs")
        .success(function (data) { $scope.logs = data.logs; });
    });
</script>

Update

If you want to load angular on the page lazily then do use angular.bootstrap that will initialize angular on the element silently. Before moving to this approach you need to remove ng-app directive from you page.

<script type="text/javascript">
    $(document).ready(function () {
        GetLogs();
    });

    function GetLogs() {
        var app = angular.module("Log", []);
        app.controller('MiscController', function ($scope, $http) {
            $http.post("/misc/getlogs")
            .success(function (data) { $scope.logs = data.logs; });
        });
        angular.bootstrap(document.body, ['Log'])
    }
</script>

You shouldn't be call the getLogs() function on document.ready angular ng-app will run first and ask for the module and will throw and module error.

So the solution would be create a angular module when page gets loaded.

<script type="text/javascript">

    var app = angular.module("Log", []);
    app.controller('MiscController', function ($scope, $http) {
        $http.post("/misc/getlogs")
        .success(function (data) { $scope.logs = data.logs; });
    });
</script>

You shouldn't be call the getLogs() function on document.ready angular ng-app will run first and ask for the module and will throw and module error.

So the solution would be create a angular module when page gets loaded.

<script type="text/javascript">

    var app = angular.module("Log", []);
    app.controller('MiscController', function ($scope, $http) {
        $http.post("/misc/getlogs")
        .success(function (data) { $scope.logs = data.logs; });
    });
</script>

Update

If you want to load angular on the page lazily then do use angular.bootstrap that will initialize angular on the element silently. Before moving to this approach you need to remove ng-app directive from you page.

<script type="text/javascript">
    $(document).ready(function () {
        GetLogs();
    });

    function GetLogs() {
        var app = angular.module("Log", []);
        app.controller('MiscController', function ($scope, $http) {
            $http.post("/misc/getlogs")
            .success(function (data) { $scope.logs = data.logs; });
        });
        angular.bootstrap(document.body, ['Log'])
    }
</script>
Source Link
Pankaj Parkar
  • 136.3k
  • 23
  • 241
  • 307

You shouldn't be call the getLogs() function on document.ready angular ng-app will run first and ask for the module and will throw and module error.

So the solution would be create a angular module when page gets loaded.

<script type="text/javascript">

    var app = angular.module("Log", []);
    app.controller('MiscController', function ($scope, $http) {
        $http.post("/misc/getlogs")
        .success(function (data) { $scope.logs = data.logs; });
    });
</script>