1

In my AngularJS controller, I have a variable $scope.name which is assigned to an input's ngModel.

I wanted to save the value of $scope.name to a normal variable, so I could process it in my controller without changing the value of the input box.

So I did var name = $scope.name

The issue is, now the two seem to be linked... when I change the value of name, the value of $scope.name also changes, and that changes the value of the input box.

How can I stop this? How can I assign a $scope variable to normal variable, once, without any continued binding?

Thank you!

1 Answer 1

1

You need to use angular.copy()

like:

var name;
$scope.name = 'name';

function copy(){
    name = angular.copy($scope.name);
}

See more

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thank you - I'll Accept this as soon as the site lets me

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.