私は現在 angularJS を学習しようとしていますが、コントローラー間のデータへのアクセスに問題があります。
最初のコントローラーは、API から通貨のリストを取得し、それを $scope.currencies に割り当てます。編集をクリックすると、別のコントローラーを使用するビューが切り替わるはずです。今、batarang を使用してデバッグすると、$scope.currencies は通貨オブジェクトの配列を表示します。
{
currencies: [{
CurrencyCode: HKD
Description: HONG KONG DOLLAR
ExchangeRateModifier: * ExchangeRate: 1
DecimalPlace: 2
}, {
CurrencyCode: USD
Description: US DOLLAR
ExchangeRateModifier: * ExchangeRate: 7.7
DecimalPlace: 2
}]
}
ただし、 を使用するangular.copy
と、$scope.copiedcurrencies
結果は null になります。
function CurrencyEditCtrl($scope, $injector, $routeParams) {
$injector.invoke(CurrencyCtrl, this, { $scope: $scope });
$scope.copiedcurrencies = angular.copy($scope.currencies);
console.log($scope.copiedcurrencies);
}