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

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.