angular.js - 关于scope中数据赋值后自动绑定的问题
PHP中文网
PHP中文网 2017-05-15 16:58:01
0
2
491

我需要复制出scope中的数据,如$scope.a给$scope.b,发现改变$scope.b时候$scope.a也会自动改变,但是我不希望他们两个之间会自动数据绑定。我用var c = $scope.a;$scope.b = c;它们之间也会自动数据绑定,应该如何做才能让它们之间不会自动绑定呢?

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!