【发布时间】:2015-06-29 23:05:12
【问题描述】:
嗨,我想以角度显示 laravel(5) 表单验证错误。 这是我的控制器:
.controller('formController', function($scope,DocParamData,$state,$http,CSRF_TOKEN) {
'use strict';
$scope.docParam = $state.current.name.split('.');
$scope.docParam = $scope.docParam[1];
// we will store all of our form data in this object
$scope.saveUser = function(user) {
$http.post('/auth/register', {
user:user,
_token:CSRF_TOKEN
}).success(function(v){
return user;
}).error(function(err) {
$scope.errors = err;
$scope.$apply();
return $scope.errors ;
});
};
$scope.getColumns = function(){
$http.get('/columns/user').
success(function(data, status, headers, config) {
$scope.user = data;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
});
和我的观点(在 register.blade.php 中嵌套'form.html'):
<div ng-repeat="e in errors">{{e}}</div>
无论我做什么 - $scope.errors 不会更新 - console.log 显示 $scope.errors 具有正确的数据,但仅在控制器中
【问题讨论】:
-
为什么需要返回 $scope.errors?这没有意义。 $scope 可以在页面的任何地方访问