backtrack
backtrack

Reputation: 8144

$scope how to use variable in angular js

I am using angular JS. Below is my Angular code

$scope.remove = function (index) {

            var name = $scope.data.Filters[index].FilterName;  

            // value of name = 'AAAA' or 'BBBB' and so on 

            $scope. data. Filters. splice (index, 1);
            $scope.Json = angular.toJson($scope.data);
        };

And my HTML is

<div><small>{{AAAA}}</small></div>
<div><small>{{BBBB}}</small></div>
<select class="BBBB"> <option> .... </select>
<select class="AAAA"> <option> .... </select>

Based on the value of name i want to reset the {{ }} vale in my view.

Say for an example Example

reset the value of {{AAAA}} if name = AAAA

so how can i use the variable name like below UPDATED

var name = $scope.data.Filters[index].FilterName;
$scope.name = "" /// How can i do like this 
$(name).selectpicker('deselectAll');

Can anyone help me

Thanks,

Upvotes: 1

Views: 56

Answers (2)

Sjoerd de Wit
Sjoerd de Wit

Reputation: 2413

If you want to display the value of name you can either do this:

<div><small ng-bind="name"></small></div>

Or you can do this:

<div><small>{{name}}</small></div>

Upvotes: 1

dfsq
dfsq

Reputation: 193261

You should use bracket notation for this. Using it you can target property of the object with the name stored in variable:

$scope[name] = '';

Upvotes: 2

Related Questions