角度应用程序数据绑定不起作用

时间:2017-12-25 17:21:46

标签: javascript angularjs linq wcf

我正在将wcf rest服务用于angular js应用程序。我正在尝试根据帐号获取帐户信息。但问题是它显示文本Account_Type三次然后显示值。

这是方法代码。

@{
    Layout = null;
}

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope, $http, $window) {
            $scope.IsVisible = false;
            $scope.Search = function () {
                var post = $http({
                    method: "GET",
                    url: "http://localhost:52098/HalifaxIISService.svc/AccountDetails/" + encodeURIComponent($scope.Account_Number),
                    dataType: 'json',
                    headers: {
                        'Accept': 'application/json, text/javascript, */*; q=0.01',
                        'Content-Type': 'application/json; charset=utf-8'
                    }
                });

                post.then(function (response) { // .success(function(data => .then(function(response
                    var data = response.data; // extract data from resposne
                    $scope.Customers = JSON.parse(data); // eval(data.d) => JSON.parse(data)
                    $scope.IsVisible = true;
                }, function (err) {
                    $window.alert(err);
                });

            }
            $scope.grandTotal = function () {
                return $scope.Customers.reduce(function (previousTotal, m) {
                    var valueToAdd = parseFloat(m.Deposit);
                    if (isNaN(valueToAdd))
                        return previousTotal;
                    return previousTotal + valueToAdd;
                }, 0); // Send in 0 as the default previousTotal
            }
            $scope.grandTotal1 = function () {
                return $scope.Customers.reduce(function (previousTotal, m) {
                    var valueToAdd = parseFloat(m.Withdrawal);
                    if (isNaN(valueToAdd))
                        return previousTotal;
                    return previousTotal + valueToAdd;
                }, 0); // Send in 0 as the default previousTotal
            }

        });
    </script>


    <div ng-app="MyApp" ng-controller="MyController">
        Account Number:
        <input type="text" ng-model="Account_Number" />
        <input type="button" value="Submit" ng-click="Search()" />
        <hr />
        <br />         


        <div ng-repeat="m in Customers" ng-show="IsVisible">Account Type:{{m.Account_Type}}</div>       



    </div>
</body>
</html>

这是代码。

 files = (FILES *)malloc(sizeof(FILES));

这是我运行应用程序时的scrren镜头。

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您需要Account_Type,则此处不需要 ng-repeat 。只需将值赋给$ scope变量

 $scope.Account_Type = details[0].Account_Type;