0

I want to pass string name through argument in function and concat in $scope, this is possible?

function test(txt){
 $scope.person. + txt; // I want to do $scope.person.status; for example
}

Thanks.

LukasMP
  • 39
  • 1
  • 7

3 Answers3

4

Yes, just do:

function test(txt){
   $scope.person[txt];
}
Omri Aharon
  • 16,959
  • 5
  • 40
  • 58
0
function test(txt){
  $scope.person[txt] = '';  // We need to assign something to it if not it wont work;
 }

Demo example : https://jsbin.com/gihizo/3/edit?html,js,console,output

KrishCdbry
  • 1,049
  • 11
  • 19
0

Check Property accessors.

As any object you can access their properties using Dot notation or Bracket notation. When you don't know before hand what property you would be accessing you would use Bracket notation ideally.

taguenizy
  • 2,140
  • 1
  • 8
  • 26