Javascript 在另一个函数内传递函数值(角度js)
我需要将一个值从一个函数传递到另一个函数。像这样: HTMLJavascript 在另一个函数内传递函数值(角度js),javascript,angularjs,Javascript,Angularjs,我需要将一个值从一个函数传递到另一个函数。像这样: HTML <div> <li ng-repeat="language in languages" ng-click="myFirstFunction(firstValue) {{language.lang}} </li> </div> <div> <li ng-repeat="age
<div>
<li ng-repeat="language in languages" ng-click="myFirstFunction(firstValue)
{{language.lang}}
</li>
</div>
<div>
<li ng-repeat="age in agess" ng-click="mySecondFunction(secondValue)
{{age.year}}
</li>
</div>
我有两个不同的函数,因为值将通过两次不同的点击到达。我需要在Mythird函数中取这2个值
谢谢。快速修改JS代码就可以了
let values = [];//place to store values
$scope.myFirstFunction = function (firstValue) {
values[0] = firstValue;//stores first value
console.log(firstValue);
}
$scope.mySecondFunction = function (secondValue) {
values[1] = secondValue;//stores second value
console.log(secondValue);
}
$scope.myThirdFunction = function () {
// you can use the values here
// console.log(values[0]);
// console.log(values[1]);
}
为什么不把它保存到
$scope
?@AlexanderStaroselsky Staroselsky我不想让IronLjnc想到$scope来认为他必须使用它,但是如果他打算将它作为一个变量来承载范围,那么我想他不会问这个问题。谢谢你@JaimeArgila,它正在为我寻找一个好的解决方案。明天我要试试!
let values = [];//place to store values
$scope.myFirstFunction = function (firstValue) {
values[0] = firstValue;//stores first value
console.log(firstValue);
}
$scope.mySecondFunction = function (secondValue) {
values[1] = secondValue;//stores second value
console.log(secondValue);
}
$scope.myThirdFunction = function () {
// you can use the values here
// console.log(values[0]);
// console.log(values[1]);
}