angular.js - Regarding the issue of automatic binding after data assignment in scope
PHP中文网
PHP中文网 2017-05-15 16:58:01
0
2
576

I need to copy the data in the scope, such as $scope.a to $scope.b. I found that when $scope.b is changed, $scope.a will automatically change, but I don’t want the two of them to automatically change. Data binding. I use var c = $scope.a;$scope.b = c; data will be automatically bound between them. What should I do to prevent them from being automatically bound?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
黄舟

Use angular.copy

Ty80

C If it is an object, a and b actually point to the same object. Using angular.copy to make a copy can solve the problem, but you may need to review whether this design is reasonable. Data-driven development should ensure that the data is consistent and unique. .

cIf it is a basic type, such as strings and numbers, the situation you mentioned should not happen

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template