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.
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.
Yes, just do:
function test(txt){
$scope.person[txt];
}
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
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.