0

I am working on creating a web page that displays data in the table. The data in the table should change when a button is clicked. (Data from different URL should be populated to the table.

I can successfully populate and show the default data. I used onclick fucntion where I have called new URL data, but it is not working

//Storing results in empData
app=angular.module('app',[]);
  app.controller('MyCtrl',function($scope,$http){
      $http.get("url")
      .success(function(response){
       $scope.empData=response;
       })
      .error(function(){
      });
     });

//this function is called on clicking the button to update the data.
function myFunction()
  {
app=angular.module('app',[]);
  app.controller('MyCtrll',function($scope,$http){

      $http.get("newurl")
      .success(function(response){
       $scope.empData=response;
       $scope.reverse=true;
       })
.error(function(){
      });
     });

Please provide me the solution to change the values of empData when the butoon is clicked

  • 1
    Put the function on the scope of the controller and use the [ng-click](https://docs.angularjs.org/api/ng/directive/ngClick) directive to invoke it. – georgeawg Jul 08 '19 at 23:19
  • The `.success` method has been [removed from the AngularJS framework](https://stackoverflow.com/questions/35329384/why-are-angularjs-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339). – georgeawg Jul 08 '19 at 23:20
  • The AngularJS Developer Guide is very good. I highly recommend it. See [AngularJS Developer Guide - Simple Spicy Controller Example](https://docs.angularjs.org/guide/controller#simple-spicy-controller-example). It shows a controller with buttons that use `ng-click` to invoke functions. – georgeawg Jul 09 '19 at 19:24

0 Answers0