这是我的 Controller 代码:
var selectableFields = ["customerName", "customerAddress"];
angular.forEach(selectableFields, function(field, key) {
var value = $.jStorage.get(field); //using jStore to get the values
$scope.field=value;
});
目的是能够访问 View 中的{{customerName}}和{{customerAddress}}。
谁能告诉我这样做的正确方法是什么?
最佳答案
请改用$scope[field] = value;
。
使用$scope.field
,您可以创建一个名为field
的新属性。
关于angularjs - 如何在Angularjs Controller 中设置动态变量名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24957925/