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] = '';
Sign up to request clarification or add additional context in comments.

6 Comments

Wow. i am out of mind and It solved my problem. Simple solutions are always difficult find. Thanks a lot
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.
Ho can i use the $(name).selectpicker('deselectAll'); it ??
I'm confused. What is name then if you use it like CSS selector?
Then try $('.' + name).selectpicker('deselectAll'); but be aware that mixing jQuery with angular like this is not very good practice.
|
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>

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.