Can a request be made in an ng-click event?

1

Can a request of the post type be made in a click event in angular?

<div  class="box-header este" data-widget="collapse" ng-click=fxRequest() >




function consulta_grupos($http, ref, vg, tipo, $scope) {

    var oficina = localStorage.getItem("numoficina");
    var vgget = globales[urlgetarchivos][oficina];

    $http({
        url: 'http://localhost:61139/servicios.svc/getgrupo',
        method: "POST",
        data: {
            referencia: ref,
            tipodoctoclave: tipo
        },
        headers: {
            'Content-Type': 'application/json; charset=utf-8',
            'dataType': 'json'
        }
    })
    .success(function (response) {

        var n = response.archivos;

        $scope.archivos = response.archivos


    }).catch(function (error) {
        console.log(error);
        //alert("Error: " + error);
    });




}
    
asked by emanuelle 24.07.2018 в 20:12
source

1 answer

2

To link a function to a div - or in short to almost any element of the DOM -, you should only do the following:

<!DOCTYPE html>
<html ng-app='App'>
  <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.2/angular.min.js"></script>
    
  </head>

  <body ng-controller='Ctrl'>
    <div style="border: 1px solid green" ng-click="click()">
      Clickea en cualquier lado
    </div>
  </body>

  <script>
    var app = angular.module('App', []);
    app.controller('Ctrl', ['$scope', function($scope){
      $scope.click = function(){
        alert();
      };
    }])
  </script>
</html>
    
answered by 24.07.2018 / 21:47
source