ng-blur操作未触发

时间:2019-04-25 12:43:53

标签: php angularjs

ng-repeat正在生成一个输入字段。输入标签包括ng-model和ng-blur。不会触发ng-blur操作,并且控制台不会显示任何错误。

HTML由Zend Framework 3应用程序生成。我正在使用angularjs 1.7.8和jquery 3.1.0。

这是网页的正文

<body ng-app='byDomainApp' ng-controller='ByDomainCtrl'>
<center>
    <h2>Maintenance By Domain</h2>
</center>
<p>You may edit/correct any of the following details. Note that an
    update will be ignored if the email address is changed to one that has
    been tried previously.</p>
<div class='row'>
    <div class='col-xs-3'>
        Choose a domain: <select class='form-control' ng-model="myDomain"
            ng-change="domainUsers(myDomain)"
            ng-options="domain.domain_name for domain in domains track by domain.domain_id"></select>
        <p ng-hide 'message=null' >
            <br> <br>{{message}}
        </p>
    </div>
</div>
<div class='row'>
    <div class='col-xs-2'>Name</div>
    <div class='col-xs-2'>Email</div>
    <div class='col-xs-2'>Company</div>
    <div class='col-xs-2'>Job title</div>
    <div class='col-xs-2'>Country</div>
    <div class='col-xs-2'>Confirmed?</div>
</div>
<div ng-repeat="user in users" class='row'>
    <div class='col-xs-2'>
        <input ng-model="user.user_name" ng-blur="updateUser(user)">
    </div>
    <div class='col-xs-2'>{{user.user_email}}</div>
    <div class='col-xs-2'>{{user.user_company}}</div>
    <div class='col-xs-2'>{{user.user_jobtitle}}</div>
    <div class='col-xs-2'>{{user.user_country}}</div>
    <div class='col-xs-2'>{{user.user_confirmed}}</div>
</div>

Javascript角度代码

angular.module('byListApp', []).constant("listUrl",
        "http://elms2.com/list-rest").constant("userUrl",
        "http://elms2.com/user-rest").controller(
        "ByListCtrl",
        function($scope, $http, listUrl, userUrl) {
            $scope.hide = true;
            $scope.showMessage = false;
            $http.get(listUrl + '/' + ownerId).then(function(response) {
                $scope.lists = response.data;
            }, function(error) {
                $scope.error = error;
                alert(error);
            });

            $scope.listUsers = function(list) {
                $scope.message = '';
                $scope.hide = true;
                $scope.showMessage = false;
                // $scope.booksFound[0].message = '';
                $http.get(userUrl + '/byList:' + list.list_id).then(
                        function(response) {
                            $scope.users = response.data;
                        });
            };
        });
angular.module('byDomainApp', []).constant("domainUrl",
        "http://elms2.com/domain-rest").constant("userUrl",
        "http://elms2.com/user-rest").controller(
        "ByDomainCtrl",
        function($scope, $http, domainUrl, userUrl) {
            $scope.hide = true;
            $scope.showMessage = false;
            $http.get(domainUrl).then(function(response) {
                $scope.domains = response.data;
            }, function(error) {
                $scope.error = error;
                alert(error);
            });

            $scope.domainUsers = function(domain) {
                $scope.message = '';
                $scope.hide = true;
                $scope.showMessage = false;
                $http.get(userUrl + '/byDomain:' + domain.domain_id).then(
                        function(response) {
                            $scope.users = response.data;
                        }, function(error) {
                            $scope.error = error;
                            alert(error);
                        });
            };

            $scope.updateUser = function(user) {
                $http.get(userUrl + '/updateUser:' + user).then(
                        function(response) {
                            $scope.userData = response.data;
                        }, function(error) {
                            $scope.error = error;
                            alert(error);
                        });
            };
        });

已正确生成域列表,并且在选择域时ng-repeat会填充正确的数据。但是,当输入字段的内容被编辑然后失去焦点时,什么也不会发生。我可以通过从角度代码中删除updateUser函数或用警报或类似内容替换ng-blur操作来证明这一点。

1 个答案:

答案 0 :(得分:0)

现在可以正常工作了,我无法解释为什么没有改变。