为什么我的范围变量会从angular.copy中丢失其值?

时间:2016-06-08 20:46:57

标签: angularjs angularjs-scope copy

每个示例看起来都应该有效,所以我会快速完成。

//点击表格行

纳克单击= “setBill(票据)”

$scope.setBill = function (bill) {
    $scope.selectedBill = angular.copy(bill);  // shouldn't this set a deep copy?
    alert($scope.selectedBill.meterNumber);  // Outputs properly
}

//点击按钮

纳克单击= “btnInsertData()”

$scope.btnInsertData = function () {
    alert($scope.selectedBill.meterNumber);    // $scope.selectedBill is undefined
    return;
}

//从上面的html请求调用

<tr ng-repeat="bill in billItems" ng-click="setBill(bill)" ng-class="{'selected':bill.meterNumber == selectedBill.meterNumber}">
    ...
    <td>{{bill.meterNumber}}</td>
    ...
</tr>
...
<button ng-click="btnInsertData()">Submit to VP</button>

0 个答案:

没有答案