0

I have this controller:

(function () {
    "use strict";

    angular.module("workPlan").controller("genericFilterDataController",    ["$scope", genericFilterDataController]);

    function genericFilterDataController($scope) {

        $scope.data = ['bla1', 'bla2', 'bla3'];

        $scope.foo = function () {

             };
        }
    })();

When function foo is fired I want to generate properties in $scope with names listed in the data array.

For example:

In function foo I want to create properties with names according to the strings in the data array:

$scope.bla1
$scope.bla2
$scope.bla3

How can I implement this?

2 Answers 2

1

Yes, in your 'foo' function:

for(var i = 0; i < data.length; i++) {
    $scope[data[i]];
}
Sign up to request clarification or add additional context in comments.

Comments

1

Did you try like this -

(function () {
"use strict";

angular.module("workPlan").controller("genericFilterDataController",    ["$scope", genericFilterDataController]);

 function genericFilterDataController($scope) {

    $scope.data = ['bla1', 'bla2', 'bla3'];

      $scope.foo = function () 
      {
        for(var i = 0; i < $scope.data.length; i++)
        {
           $scope[$scope.data[i]] = $scope.data[i];// or your data point here
         }

      };
    }
})();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.