1

I am new to anuglar Js. I am trying to figure out How do i change the property value.

 $scope.dashboards = {
                        "1": {
                            "widgets": [{
                                "row": 0,
                                "col": 0,
                                "sizeX": 2,
                                "sizeY": 1,
                                "name": "Canvas 1",
                                "canvas": "canvas_1",
                                "show": true
                            }, {
                                "row": 0,
                                "col": 2,
                                "sizeX": 2,
                                "sizeY": 1,
                                "name": "Canvas 2",
                                "canvas": "canvas_2",
                                "show": true
                            }]
                            }
                     }

On ng-click , i want to change the value of key "show" to false.

<div gridster-item="widget" ng-repeat="widget in dashboard.widgets">
    <i ng-click="changeValue(widget)" class="glyphicon glyphicon-trash">
</div>

$scope.changeValue= function (widget) {
            .....How to??
        };
1
  • do U want to change all show property value? Commented Oct 28, 2015 at 10:07

4 Answers 4

2

Since you are already passing the current widget as a parameter, you can do Like this

$scope.changeValue= function (widget) {
        widget.show = false;
    };
Sign up to request clarification or add additional context in comments.

Comments

2

I would not pass the widget. Instead I would pass its $index:

<i ng-click="changeValue($index)" class="glyphicon glyphicon-trash">

And then:

$scope.changeValue= function (index) {
   $scope.dashboards.1.widgets[index].show = ...
};

Comments

0

It's look like your array in ng-repeat is undefined in scope. You should update your codes like below;

<div gridster-item="widget" ng-repeat="widget in dashboards.1.widgets">
    <i ng-click="changeValue(widget)" class="glyphicon glyphicon-trash">
</div>

After you get related object and update show property in $scope like below:

$scope.changeValue= function (widget) {
   $scope.dashboards.1.widgets[widget].show = false;      
};

Comments

0

Simply,

$scope.changevalue= function(widget){
  for (var i = 0; i < $scope.dashboards.length; i++) {
    for (var j = 0; j < $scope.dashboards[i].widgets.length; j++) {
        if ($scope.dashboards[i].widgets[j].ID == widget.ID){
            $scope.dashboards[i].widgets[j].show= false
        }
    };  
  };      
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.