Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在没有发生错误时排除角度视图故障_Angularjs - Fatal编程技术网

Angularjs 在没有发生错误时排除角度视图故障

Angularjs 在没有发生错误时排除角度视图故障,angularjs,Angularjs,我开始学习角度,我有这个问题。我使用REST从web服务获取数据,然后将此数据作为数据传递给控制器。d.results,我签入开发人员工具和结果。长度为11,一切正常。我修改了html以包含ng应用程序、ng控制器。控制器包装的HTML如下所示: <table ng-controller="ListsController as vm"> <thead> <tr&

我开始学习角度,我有这个问题。我使用REST从web服务获取数据,然后将此数据作为
数据传递给控制器。d.results
,我签入开发人员工具和结果。长度为11,一切正常。我修改了html以包含
ng应用程序、ng控制器
。控制器包装的HTML如下所示:

 <table ng-controller="ListsController as vm">
                        <thead>
                            <tr>
                                <td>Image</td>
                                <td>Product</td>
                                <td>Code</td>
                                <td>Available</td>
                                <td>Price</td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="product in vm.products">
                                <td>
                                    <img ng-src="{{product.ImageUrl.Url}}" title="{{product.Title}}" style="width: 50px;margin:2px;" />
                                </td>
                                <td>{{product.Title}}</td>
                                <td>{{product.ProductCode}}</td>
                                <td>{{product.ReleaseDate}}</td>
                                <td>{{product.Price | currency}}</td>
                            </tr>
                        </tbody>
                    </table>
(function () {
angular
    .module("sitemanagerapp")
    .controller("ListsController",
                ListsController);

function ListsController() {
    var vm = this;
    var getProducts = getAllItems('Products');
    getProducts
        .done(function (data, status, jqXHR) {
            vm.products = data.d.results;
        })
        .fail(function (jqXHR, status, error) {
            LogError(error);
        });
   }
}());

我正在签入开发人员工具,最后,vm.products将填充来自服务的数据。但为什么我的表格里并没有数据呢?如何解决与此相关的问题?没有为我或任何东西显示错误

我想您的
getProducts
不是用angular的
$http
$resource
实现的
在这种情况下,为了实现您的目标,您必须将
$scope
注入控制器,即使您正在使用
controllerAs
语法

(function () {
angular
    .module("sitemanagerapp")
    .controller("ListsController",
                ['$scope', ListsController]);

function ListsController($scope) {
    var vm = this;
    var getProducts = getAllItems('Products');
    getProducts
        .done(function (data, status, jqXHR) {
            vm.products = data.d.results;
            $scope.$apply();
        })
        .fail(function (jqXHR, status, error) {
            LogError(error);
        });
   }
})();

你把括号按错误的顺序放在最后一行。它应该是
}()
这是一个函数表达式,IFFE。我不认为这是错的。我的问题不是IFFE,而是从异步服务得到响应后刷新数据。正如我所说,我将数据返回到vm.products。它只是不更新用户界面。我不能使用vm。$apply(),在我的情况下如何使用$apply。谢谢