如何通过数组更新角度子范围

How to update angular child scope by an array

本文关键字:范围 更新 何通过 数组      更新时间:2023-09-26

我正在从服务器获取一组数据,并将更新angularJS中的$scope

初始值为:

$scope.form = {};

我想像这样动态更新:

$scope.form = {"firstname" : "Alex"};

firstnamealex都必须通过如下数组进行更新:

sent.then(function(result) {
  angular.forEach(result.data.test, function(value, key){
    // ** something like this, but it doesn't work :
    var form_child = "{" + value.FieldName + ":" + value.FieldValue "}";
    $scope.form = form_child;
  });
});

我该怎么做**行?

使用数组语法:

$scope.form[value.FieldName] = value.FieldValue;

在angular中,您不能访问子作用域,只能访问父作用域。