简体   繁体   中英

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. lets say i call the function using $scope.clicked('yes','i am yes') . I want $scope.yes = 'i am yes'; what i get is $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] is right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM