gpt4 book ai didi

javascript - AngularJS 动态 url

转载 作者:行者123 更新时间:2023-12-01 17:19:32 25 4
gpt4 key购买 nike

例如我的页面上有 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 如何做到这一点

最佳答案

试试这个

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>

关于javascript - AngularJS 动态 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59245779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com