0

I have a function in my controller and it receives a parameter called let's say time, I'd like to refer to a ng-model in my scope based on that parameter.

What I have:

$scope.myFunction = function(){
  $scope.minutes = 1;
}

What I want:

$scope.myFunction = function(time){
  $scope.time = 1;
}

Where time is the parameter received and has the value minutes.

Thanks

1 Answer 1

2

If you are getting the variable name as a parameter:

$scope.myFunction = function(propName) {
  $scope[propName] = 1;
};
Sign up to request clarification or add additional context in comments.

1 Comment

Yes. I think that is what the OP is after. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.