2

I really don't no this angularjs variable working.

look at the my code -> http://jsfiddle.net/a9etkyz7/1/

$scope.ref and $scope.ref2 is not working!

$scope.ref= $scope.a

this is not reference?

this is copy?

please tell me answer

1
  • What do you want to do here? Commented Sep 11, 2014 at 1:55

1 Answer 1

1

Only objects can be passed as reference, since $scope.a is assigned a primitive value, then changes to the assigned values in $scope.ref and $scope.ref2 does not reflect to the changes of $scope.a.

Tol solve this, you can change $scope.a into an object that holds a reference to the value you wish to change, and assign it to both $scope.ref1 and $scope.ref2.

DEMO

JAVASCRIPT

Controller

//....
$scope.a = {value: 12};
$scope.ref = $scope.a;
$scope.ref2 = {copyVale2: $scope.a};

Directive

//....
scope.a.value = newVal;

HTML

<test value="value" a="a">
    <div>ref a : {{ref.value}}</div>
    <div>ref2 a : {{ref2.copyVale2.value}}</div>
    <div>a : {{a.value}}</div>
</test>
Sign up to request clarification or add additional context in comments.

2 Comments

umm, i have one more question. why only objects can be passed as reference? why not working not object?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.