我是一个真正的AngularJS和JS noob,他们试图在用户双击某个元素时显示一个输入,但是,我无法正常工作。当前我有此错误... TypeError:无法设置未定义的属性“编辑”

这是我的代码...

var reportsControllers = angular.module('vdApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

reportsControllers.controller('ApplicantCtrl', ['$scope', '$http', function($scope, $http) {
    $http.get('http://myurl.com').success(function(data)
    {
        $scope.applicants = data;
    });

    angular.forEach($scope.applicants, function() {
        editing: false;
    });

    $scope.orderProp = 'dob';

    $scope.editApplicant = function(applicant) {
        applicant.editing = true;
    };

    $scope.doneEditing = function(applicant) {
        applicant.editing = true;
    };

}]);


和我的HTML /刀片模板...

<div ng-app="vdApp" ng-controller="ApplicantCtrl">
    <div class="input-group spacer-bottom-2x">
        <span class="input-group-btn"><button class="btn btn-default btn-lg" type="button">Filter:</button></span>
        <input class="form-control input-lg" ng-model="query" />
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th width="15%"><a href="" ng-click="orderProp='fname'">Name</a></th>
                    <th width="10%"><a href="" ng-click="orderProp='surname'">DOB</a></th>
                    <th width="5%">CV</th>
                    <th width="25%"><a href="" ng-click="orderProp=''">Tel</a></th>
                    <th width="25%"><a href="" ng-click="orderProp=''">Email</a></th>
                    <th width="10%"><a href="" ng-click="orderProp='postTown'">Post Town</a></th>
                    <th width="20%"><a href="" ng-click="orderProp='page_title'">Interest</a></th>
                    <th width="10%"><a href="" ng-click="orderProp='created_at'">Applied</a></th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="app in applicants| filter: query | orderBy: orderProp">
                    <td>[[ app.fname ]] [[ app.surname ]]</td>
                    <td>[[ app.dob ]]</td>
                    <td><div ng-if="app.cv != ''"><a href="[[ app.cv ]]" target="_blank">View</a></div></td>
                    <td >
                        <span ng-hide="applicant.editing" ng-dblclick="editApplicant(applicant)">[[ app.tel ]]</span>
                        <div class="form-group" ng-show="applicant.editing" ng-model="app.id" ng-blur="doneEditing(applicant)" autofocus>
                            <input class="form-control input-lg" ng-model="query" />
                        </div>
                    </td>
                    <td>[[ app.email ]]</td>
                    <td>[[ app.postTown ]]</td>
                    <td>[[ app.page_title ]]</td>
                    <td>[[ app.created_at ]]</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>


谁能帮助我,告诉我我做错了什么?

谢谢!

最佳答案

您将转发器声明为ng-repeat="app in applicants",然后尝试ng-dblclick="editApplicant(applicant)ng-show="applicant.editing"

applicant不存在-您应该使用中继器循环变量app

10-06 14:40