【问题标题】:angular $scope not updating with validation errors coming from laravel角度 $scope 没有更新来自 laravel 的验证错误
【发布时间】: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 可以在页面的任何地方访问

标签: angularjs laravel


【解决方案1】:

尝试使用angular.merge

angular.merge(object1, object2);

【讨论】:

  • 合并 $scope 与什么先生? @Balram Khichar
  • 创建一个空数组 $scope.errors = [];然后使用angular.mege($scope.errors, res);
  • 确保您的 res 格式正确
  • 尝试合并,格式正确。 console.log() 显示错误。但仍然没有显示在 html 中。当我对数组进行编码时,它就可以工作了..
  • 你能把你的res数据格式粘贴到这里吗?
猜你喜欢
  • 2016-02-09
  • 1970-01-01
  • 2015-04-30
  • 2014-06-11
  • 1970-01-01
  • 2016-01-14
  • 2021-12-05
  • 1970-01-01
  • 2017-10-21
相关资源
最近更新 更多