Mohamad Shiralizadeh
Mohamad Shiralizadeh

Reputation: 8765

How does angular watch changes in a model?

How does angular watch changes in a model?

app.controller('ProjectsController', function (ProjectsRepository) {
    var pj = this;

    pj.PageIndex = 1;
    pj.PageSize = 50;

    var req = ProjectsRepository.Get(pj);

    faraAjaxConfig(req)
        .success(function (result) {
            console.log(result);
            if (result.Success) {
                pj.Rows = result.Rows; // How detect changes in this and apply to ng-repeat
            }
            else {
                faraAjaxMessage(result.Messages, true);
            }
        });
});

Upvotes: 0

Views: 154

Answers (1)

Dylan Watt
Dylan Watt

Reputation: 3387

It looks like you're not using the built in $http, which means you'll need to $scope.$apply() to kick off a digest cycle, which is where angular does its checking. In general, any data retrieved from an async source not using an angular service will need to notify angular of the changes this way. Websockets, ajax, web workers, etc.

(I'd recommend just using $http instead, cleaner all around)

app.controller('ProjectsController', function (ProjectsRepository, $scope) {
    var pj = this;

    pj.PageIndex = 1;
    pj.PageSize = 50;

    var req = ProjectsRepository.Get(pj);

    faraAjaxConfig(req)
        .success(function (result) {
            console.log(result);
            if (result.Success) {
                pj.Rows = result.Rows; // How detect changes in this and apply to ng-repeat
            }
            else {
                faraAjaxMessage(result.Messages, true);
            }
            $scope.$apply();
        });
});

Upvotes: 2

Related Questions