使用angular js中的另一个变量来获取$scope.x1变量

To get the $scope.x1 variable using the another variable in angular js

本文关键字:变量 获取 scope x1 另一个 angular js 使用      更新时间:2023-09-26

有一个变量名的数组

$scope.intialArray =[];
$scope.intialArray[0] ='x1';
$scope.intialArray[1] ='x2';

这些值在控制器中计算

$scope.x1 = 'somevalue';
$scope.x2 ='another value';

现在我想用intailArray程序化地获取各种名称下面的代码。

$scope.($$scope.intialArray[0].val);

你能帮我在angularjs 中进行变量评估吗?

$scope[$scope.intialArray[0]];

尝试这种方式:)