0

すべての角の範囲入力を移動すると、残りの入力は正常に機能しますが、別の角の範囲を移動すると、すべての角が 1 ~ 3 ピクセル移動します。ここで何が問題になる可能性がありますか?

デモはこちら: http://jsfiddle.net/g10fsxym/

コード:

var myApp = angular.module('myApp', []);

myApp.controller('myAppCtrlr', function($scope) {

var allcorners = new Quantity(5);
var topLeft = new Quantity(5);
var topRight = new Quantity(5);
var bottomLeft = new Quantity(5);
var bottomRight = new Quantity(5);

$scope.brCorners = allcorners;
$scope.brTopLeft = topLeft;
$scope.brBottomLeft = bottomLeft;
$scope.brTopRight = topRight;
$scope.brBottomRight = bottomRight;

$scope.brTopLeftCorner = function() {
    $scope.brTopLeft = topLeft;
}
$scope.brBottomLeftCorner = function() {
    $scope.brBottomLeft = bottomLeft;
}
$scope.brTopRightCorner = function() {
    $scope.brTopRight = topRight;
}
$scope.brBottomRightCorner = function() {
    $scope.brBottomRight = bottomRight;
}

$scope.brAllCorners = function() {
    $scope.brTopLeft = $scope.brCorners;
    $scope.brTopRight = $scope.brCorners;
    $scope.brBottomLeft = $scope.brCorners;
    $scope.brBottomRight = $scope.brCorners;
}});
function Quantity(value) {
var qty = value;
this.__defineGetter__("qty", function() {
    return qty;
});
this.__defineSetter__("qty", function(val) {
    val = parseInt(val);
    qty = val;
});}`
4

1 に答える 1

0

のコピーを作成するだけです$scope.brCorners(そうしないと、参照を使用しているため、1 つの変数を変更すると別の変数も変更されます)。

デモ

    $scope.brAllCorners = function() {
      $scope.brTopLeft = angular.copy($scope.brCorners);
      $scope.brTopRight = angular.copy($scope.brCorners);
      $scope.brBottomLeft = angular.copy($scope.brCorners);
      $scope.brBottomRight = angular.copy($scope.brCorners);
    } 
于 2015-04-08T13:44:23.133 に答える