3

For example I have 3 links on my page: A B C,

When I click A it should function something like this

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $http.get("some.url/A")
  .then(function(response) {
    $scope.myWelcome = response.data;
  });
});

"A" should dynamically reach the url when I click A. How to do it angularJs

georgeawg
  • 48,608
  • 13
  • 72
  • 95

1 Answers1

0

try this

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $scope.myFunc = function(url) {
      console.log(url);
      $http.get("some.url/"+url)
      .then(function(response) {
          $scope.myWelcome = response.data;
      });
  };
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="myApp">
    <div ng-controller="myCtrl">
        <button ng-click="myFunc('A')">A</button>
        <button ng-click="myFunc('B')">B</button>
        <button ng-click="myFunc('C')">C</button>
    </div>
</body>
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Mohammad Ali Rony
  • 4,695
  • 3
  • 19
  • 33