Q:

Ng-show not updating after value changed

JS
$scope.getDiffs = function () {
    return Module.getDiffs($scope.item.account_id, $scope.item.year)
      .then(function (res) {
        angular.forEach(res, function (v) {
            angular.forEach($scope.months, function (m) {
                if (m.month == v.month) {
                    m.diff = v.diff != 0;
                }
            });
        });
    });
};

Blade
<ul class="nav nav-tabs mbtm-10">
    <li role="presentation" ng-repeat="m in months"
        ng-class="{active: item.month == m.month}">
        <a href="" ng-click="item.month = m.month;fetchTrx()">
            @{{m.text}}
          <i ng-show="m.diff != null" class="fa fa-circle"
             ng-class="{'text-success': !m.diff, 'text-danger': m.diff}">
          </i>
        </a>
    </li>
</ul>

My code will show the green circle on the taps interface if the value is m.diff != null. However, It will not updating if value is m.diff == null. Once the tap is show the green circle then it show forever green circle no matter in what value.

A:

Use angular.copy:
$scope.getDiffs = function () {
    return Module.getDiffs($scope.item.account_id, $scope.item.year)
      .then(function (res) {
        angular.forEach(res, function (v) {
            angular.forEach($scope.months, function (m,i,arr) {
                if (m.month == v.month) {
                    m.diff = v.diff != 0;
                    arr[i] = angular.copy(m);
                }
            });
        });
    });
};

