0

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.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • It's a little hard to know without knowing how the results look. The best way is if you could create a working [snippet](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do?rq=1) so we could actually see the problem. I know that it's not an easy task but for getting good answers you have to asking good questions :) – Mosh Feu Apr 07 '19 at 16:23
  • If I would have to guess, there is no `$digest` run after the change. So whether `Module.getDiffs` should return an angularjs [`promise`](https://docs.angularjs.org/api/ng/service/$q) (if it's not) or you can call `$scope.apply` after the change. https://stackoverflow.com/a/35072391/863110 – Mosh Feu Apr 07 '19 at 16:26
  • Why does the code use `ng-show="m.diff != null"`? It looks like it is set to either `true` or `false`. The `null` value is an object, not a boolean. – georgeawg Apr 07 '19 at 17:01

1 Answers1

0

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);
                }
            });
        });
    });
};
georgeawg
  • 48,608
  • 13
  • 72
  • 95