Angularjs 角度表在模型中是如何变化的?

Angularjs 角度表在模型中是如何变化的?,angularjs,Angularjs,角度表在模型中是如何变化的 app.controller('ProjectsController', function (ProjectsRepository) { var pj = this; pj.PageIndex = 1; pj.PageSize = 50; var req = ProjectsRepository.Get(pj); faraAjaxConfig(req) .success(function (result)

角度表在模型中是如何变化的

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

看起来您没有使用内置的
$http
,这意味着您需要
$scope.$apply()
启动摘要循环,angular在这里进行检查。通常,从不使用angular服务的异步源检索的任何数据都需要以这种方式通知angular的更改。WebSocket、ajax、web工作者等

(我建议只使用$http,更干净)


本视频演示如何在30分钟内从头开始重写angular,并解释其内部工作原理:
ProjectsRepository.Get(pj)
使用
$http
什么是faraAjaxConfig?它似乎不知从何而来。@Mohamadshiralizadeh当函数调用从angular应用程序中传出时,您需要$scope.$apply()来启动一个摘要循环。@DylanWatt
faraAjaxConfig
只需在req中添加一些函数:
函数faraAjaxConfig(promis){promis.success(函数(){//success})。错误(函数(){//error}).finally(函数(){//finally});返回promis;}
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();
        });
});