1

I have tried various ways but nothing works for me. What I have:

app.controller('someCtrl',
...

$scope.load = function () {
    client.loadAgreements().
        then(function (response) {
            $scope.unapprovedCount = response.data[StatusTypeEnum.Unapproved];
            $scope.approvedCount = response.data[StatusTypeEnum.Approved];

            $scope.$apply();
        });
};

Html part:

<button text="'({{unapprovedCount}})'" ...
<button text="'({{approvedCount}})'"...

When I do:

app.controller('someCtrl',
...

$scope.unapprovedCount = 777;

$scope.load = function () {
    client.loadAgreements().
        then(function (response) {
            $scope.unapprovedCount = response.data[StatusTypeEnum.Unapproved];
            $scope.approvedCount = response.data[StatusTypeEnum.Approved];

            $scope.$apply();
        });
};

I can see 777 when page renders. However I don't see any updates from promise. Variable is assigned but view is not updated. And if I add apply method then I am getting error:

Error: [$rootScope:inprog] $digest already in progress

What else can I try, as I am new to angular and don't know how to do this?

EDIT:

I am not sure if this matters but actually this button uses directive:

<button ng-fas-button-with-color-indicator text"'Approved  ({{unapprovedCount}})'" color="red" ...

And text is rendered in some div.

2
  • did u console the response.data[StatusTypeEnum.Unapproved] Commented Jun 27, 2016 at 12:23
  • Sure, in debug mode I see that $scope.unapprovedCount is assigned a proper value in then part. Commented Jun 27, 2016 at 12:32

2 Answers 2

1

Remove

$scope.$apply();

from your code and check in your console the value of

response.data[StatusTypeEnum.Unapproved]
Sign up to request clarification or add additional context in comments.

3 Comments

When I debug I see that $scope.unapprovedCount is assigned proper number.
When load function is called ? Have you got the same issue with approvedCount ?
Sure, in debug mode I see that $scope.unapprovedCount is assigned a proper value in then part. If I assign this variable manually some value outside load function then it works.
0

Why you need the $scope.$apply()?

You have to remove it from your code.

The only need of this function is when you are using a third party lib to manipulate variable from the scope, outside of angular's watch.

When you use apply and the digest cycle is ok, nothing changed, will raise this error.

2 Comments

I am not sure, but when I saw that my view is not updated I googled and I read that angular can not know that my variable changed when async call ended and I need to manually call digest.
@GiorgiNakeuri can you post the loadAgreements function?

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.