0

I need to initialized without binding.

I've tried the following. But I did not succeed

$scope.emptyRow = $scope.newsCategories[1];
$scope.newsCategories[1].Name = "yes";
$scope.emptyRow.Name = "test";
alert($scope.emptyRow.Name); // alert => test
alert($scope.newsCategories[1].Name);// alert => test

I need this :

$scope.emptyRow = $scope.newsCategories[1];
$scope.newsCategories[1].Name = "yes";
$scope.emptyRow.Name = "test";
alert($scope.emptyRow.Name); // alert => test
alert($scope.newsCategories[1].Name);// alert => yes

How to do this?

1 Answer 1

2

This has nothing to do with binding, but rather basic javascript.

The line: $scope.emptyRow = $scope.newsCategories[1];

is explicitly saying that you want $scope.emptyRow and $scope.newsCategories[1] to be pointing to the exact same object. Hence, when you change a child value of either (like Name), it will effect the other.

It looks like you want to be able to copy the object in question. For that you can use angular.copy(). An example use in your case would be:

$scope.emptyRow = angular.copy($scope.newsCategories[1]);

Read here for more info.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.