Ng-show在值更改后未更新

问题描述 投票:0回答:1

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;
                }
            });
        });
    });
};

<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>

如果值为m.diff != null,我的代码将在点击界面上显示绿色圆圈。但是,如果值为m.diff == null,则不会更新。一旦水龙头显示绿色圆圈,它就会显示永远的绿色圆圈,无论价值是多少。

angularjs laravel-blade
1个回答
0
投票

使用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);
                }
            });
        });
    });
};
© www.soinside.com 2019 - 2024. All rights reserved.