【问题标题】:AngularJS dynamic urlsAngularJS 动态网址
【发布时间】:2019-12-09 09:19:59
【问题描述】:

例如,我的页面上有 3 个链接: 一种 乙 C,

当我点击 A 时,它的功能应该是这样的

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

当我点击A时,“A”应该动态到达url。如何做到angularJs

【问题讨论】:

    标签: javascript angularjs dynamic-url


    【解决方案1】:

    试试这个

    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>

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 2013-06-09
      • 1970-01-01
      • 2013-11-29
      • 2021-04-27
      • 2013-08-17
      • 2012-03-15
      • 2011-01-10
      • 2012-04-17
      相关资源
      最近更新 更多