samedi 25 avril 2015

How to update model after making json get request? (Angular JS)


I have a simple page that shows set of records according to year. Just a note, the sidebar is not highlighting selection properly.

enter image description here

I am able to load the data the first time i come to this page. But when i try to change year and hit go, the main content area goes blank and the url changes to localhost:8080/cg/

Here is my controller code.

        app.controller('AnnualReportController', ['$scope', '$http', function ($scope, $http) {

            $scope.annuals = [];
            $scope.selection = 0; // gives me the year value from the drop down.

            // initial load that works
            $http.get('annualReport/list').success(function (data) {
                $scope.annuals = data;
                $scope.selection = data.year;
            });


            // on-click event for 'Go'  
            $scope.searchGo = function () {
                $http.get('annualReport/list', {params: {year:$scope.selection}
                }).success(function (data) {
                    $scope.annuals = data;
                    $scope.selection = data.year;
                });
            }
        }]);

Can someone please tell mew how i can update the model and view my data?


Aucun commentaire:

Enregistrer un commentaire