snazzybouche snazzybouche - 11 months ago 51
AngularJS Question

How to bind a $scope variable to a normal variable in AngularJS?

In my AngularJS controller, I have a variable

which is assigned to an input's

I wanted to save the value of
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 = $

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

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

Thank you!


You need to use angular.copy()


var name;
$ = 'name';

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

See more