1

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,

2 Answers 2

2

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

$scope[name] = '';
6
  • Wow. i am out of mind and It solved my problem. Simple solutions are always difficult find. Thanks a lot
    – backtrack
    Commented Nov 27, 2014 at 10:36
  • Glad it helped you. When you use dot notation like $scope.name it's interpreted literally as property name of the object $scope. With bracket syntax you can provide any variable name.
    – dfsq
    Commented Nov 27, 2014 at 10:38
  • Ho can i use the $(name).selectpicker('deselectAll'); it ??
    – backtrack
    Commented Nov 27, 2014 at 10:40
  • I'm confused. What is name then if you use it like CSS selector?
    – dfsq
    Commented Nov 27, 2014 at 10:43
  • 1
    Then try $('.' + name).selectpicker('deselectAll'); but be aware that mixing jQuery with angular like this is not very good practice.
    – dfsq
    Commented Nov 27, 2014 at 10:58
1

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>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.