当我尝试通过添加指令对“名称”字段进行服务器端验证时:
 app.directive('uniqueName', function($http) {
    var toId;
    return {
        require: 'ngModel',
        link: function(scope, elem, attr, ctrl) {
 
            scope.$watch(attr.ngModel, function(value) {
                    $http.get('/rest/isUerExist/' + value).success(function(data) {
                        //set the validity of the field
                        $scope.$apply(function(s) {
                            ctrl.$setValidity('uniqueName', data);
                        });
                    });
            })
        }
    }
});
为什么它在控制台中返回“$scope 未定义”消息?
更新:
如果我使用“范围”。但不是“$scope。”,那么我在控制台中有不同的错误:
错误:$digest 已经在进行中