How to set dynamic variable name in Angularjs controller

This is my controller code:

var selectableFields = ["customerName", "customerAddress"]; angular.forEach(selectableFields, function(field, key) { var value = $.jStorage.get(field); //using jStore to get the values $scope.field=value; }); 

The goal is to have access to {{customerName}} and {{customerAddress}} in the view. Can someone please tell me how to do it right?

+6
source share
1 answer

Use $scope[field] = value; instead of this.

Using $scope.field you create a new attribute called field .

+22
source

Source: https://habr.com/ru/post/972839/


All Articles