[英]pass scope object's key value form function input angularjs
pardon me if this is a repeat question and i am still a beginner. 如果这是一个重复的问题,请原谅我,但我仍然是初学者。
see the code below : 参见下面的代码:
$scope.clicked=function(key,value){
$scope[key]=value;}
the above code returns $scope.key
is undefined or $scope.key=value
even if i pass any value to key. 上面的代码返回$scope.key
是未定义的或$scope.key=value
即使我将任何值传递给key。 lets say i call the function using $scope.clicked('yes','i am yes')
. 可以说我使用$scope.clicked('yes','i am yes')
调用函数。 I want $scope.yes = 'i am yes';
我想要$scope.yes = 'i am yes';
what i get is $scope.keys='i am yes';
我得到的是$scope.keys='i am yes';
. 。 how do i achieve what i want.? 我如何实现我想要的?
$scope.clicked=function(key,value){
$scope[key]=value;}
You are using incorrect Syntax $scope.[key] is wrong. 您使用的语法不正确$ scope。[key]是错误的。 $scope[key] is right. $ scope [key]是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.