0

I'm trying to pass in a variable a function that will change the scope the data I am receiving will be put into. I am having some trouble getting this to work - so I'm not sure if this is the correct way of doing this. Here's what I'm doing -

$scope.upload = function(element, type){
    //call function
    .success(function(){
        //in success put data in our new scope
        $scope.type = data;
    })

So what I'm trying to achieve is the call to this function would set the scope name by sending the type. The problem I ( I think) I am having, is angular inst recognizing the variable when I put $scope. in front of it, so when I try to drop the variable as a new scope in $scope.type, I believe it thinks I just mean "$scope.type" not $scope.(my variable passed in). IS something like this possible? Maybe I have to escape something in here?

Thanks for reading!

1 Answer 1

2

Use bracket notation ($scope is just an object afterall):

$scope[type] = data;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.