首页 > 解决方案 > 重新加载或刷新正在 AngularJs 视图中呈现 Json 字符串

问题描述

我正在尝试在 angularJS 中上传 json 对象数组。第一次,单击链接时,工作正常。但刷新/重新加载页面后,视图消失并显示 JSON 字符串。请有人帮忙解决问题吗?

控制器:-

angular.module('app.failureNotify', []).controller('failureNotifyController',
    function($scope, failureNotifyService) {

        failureNotifyService.failureNotify().then(function(response) {
            $scope.failureNotifyResponse = [];
            $scope.failureNotifyResponse = response.data;

        });
    })

HTML:-

<div class="container" ng-controller="failureNotifyController">
<div class="row">
    <div class="col-lg-8">
        <h3>Controller list</h3>
    </div>
</div>
<br /> <br /> <b>From Date</b> : &nbsp;<input type="text" name="from"
    ng-model="from"> <br /> <br /> <b>To Date &nbsp; &nbsp;
    &nbsp; </b>: &nbsp;<input type="text" name="to" ng-model="to"> <br />
<br />
<div class="row">
    <div class="col-lg-8">
        <table>
            <tr>
                <th>Account Number</th>
                <th>Account Type</th>

            </tr>
            <tr
                ng-repeat="failures in failureNotifyResponse">
                <td>{{failures.accountNumber}}</td>
                <td>{{failures.accountType }}</td>

            </tr>
        </table>
    </div>
</div>

服务:-

angular
    .module('app.services', [])
        .service(
            'failureNotifyService',
            [
                    '$http',
                    function($http) {
                        this.failureNotify = function failureNotify() 
                        {
                            return $http({
                                method : 'GET',
                                url : '/failureNotify',

                            })
                        }
                    } ])

刷新后:

标签: angularjsangularjs-directiveangularjs-ng-repeat

解决方案


推荐阅读