简体   繁体   English

Angular 1.3:TypeError:无法在 ng-submit 上读取空错误的属性“0”

[英]Angular 1.3 : TypeError: Cannot read property '0' of null error on ng-submit

I have a simple form that I am trying to submit but it is giving me error:我有一个简单的表单,我正在尝试提交,但它给了我错误:

TypeError: Cannot read property '0' of null.类型错误:无法读取 null 的属性“0”。

I removed almost everything but it is still giving me error.我删除了几乎所有内容,但它仍然给我错误。 I don't know why.我不知道为什么。

Here is the code.这是代码。

<body id="home" ng-app="formApp">
    <div ng-controller="formRegister">
<form name="formprofile3" method="post" id="formprofile3" role="form" ng-submit="formprofile3()">
<!--<div class="form-group">
<input type="text" id="fname" name="fname" placeholder="Your Name" ng-model="formData.fname" title="Please Enter Your First Name" class="form-control input-sm" required="required">
</div>
 
<div class="form-group">
<input type="email" id="email" name="email" placeholder="Your Email" ng-model="formData.email" class="form-control input-sm" title="Please Enter Your Valid Email" required="required">
</div>
<div class="form-group">
<input type="text" name="subject" id="subject" placeholder="Subject" ng-model="formData.subject" title="Please enter Subject" class="form-control input-sm" required="required">
</div>
 
<div class="form-group">
<textarea name="message" id="message" placeholder="Message" title="Please enter your message/concern/query" ng-model="formData.msg" class="form-control input-sm" required="required"></textarea>
 
</div>  -->  

<div class="form-group">
<button type="submit" class="btn btn-home" name="btn-register" id="btn-register" required="required">Submit</button>
 
</div>
</form>

Angular Code.角码。

    var formApp = angular.module('formApp', []);

formApp.controller('formRegister', function($scope,$http){
      
            $scope.formData = {};
    
    $scope.formprofile3 = function() {
                       alert('hi');
      /*       var allData={'formData': $scope.formData}
        $http({
              method  : 'POST',
              url     : 'http://xyzcom/contact.php',
              data : allData,
              headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  
          })
              .success(function(data) {
                   if (!data.success) {
 
                      $scope.message = data.errors.message;
                   
                  }else{
                   $scope.message = '';
                      alert('Your message has been sent.');
                      location.href = './profile.html';
                  }

              });*/
                   };

As you can see most of them are comment out but still I am getting error.正如您所看到的,它们中的大多数都被注释掉了,但我仍然遇到错误。

Here, form is considered as angular directive which instantiate FormController .在这里, form被认为是实例化FormController 的角度指令。 If the name attribute of form directive is specified, the form controller is published onto the current scope under this name.如果指定了form指令的name属性,则表单控制器将发布到此名称下的当前范围。 So when you're writing ng-submit function name same as form name attribute it try to (search and) execute in that newly created scope.因此,当您编写与表单名称属性相同的 ng-submit 函数名称时,它会尝试(搜索和)在新创建的范围内执行。 Name that function other than form name & issue will be solved.命名表单名称和问题以外的功能将被解决。

Example: Plunker (Change form name to same as ng-submit function to reproduce the issue).示例: Plunker (将表单名称更改为与 ng-submit 函数相同以重现该问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取 null 的属性“错误” - Uncaught TypeError: Cannot read property 'error' of null 错误类型错误:无法读取 null 的属性“3” - ERROR TypeError: Cannot read property '3' of null ng-submit angular js在php中不起作用 - ng-submit angular js not working in php 我正在使用angular 2 angular-cli并尝试使用ng2-datetime,但出现错误“ TypeError:无法读取未定义的属性&#39;jQuery&#39;” - I am using angular 2 angular-cli and try to use ng2-datetime,but it give error “TypeError: Cannot read property 'jQuery' of undefined” JSON或Jquery错误:未捕获的TypeError:无法读取null的属性“错误” - JSON or Jquery error: Uncaught TypeError: Cannot read property 'error' of null 如何删除此错误“未捕获的TypeError:无法读取null的属性&#39;translatedText&#39;” - how to remove this error “Uncaught TypeError: Cannot read property 'translatedText' of null ” JS错误未捕获的TypeError:无法读取null的属性“ top” - JS Error Uncaught TypeError: Cannot read property 'top' of null 控制台中的错误:未捕获的类型错误:无法读取 null 的属性“getAttribute” - Error in console: Uncaught TypeError: Cannot read property 'getAttribute' of null 获取错误为:未捕获的TypeError:无法读取null的属性“ parentNode” - Getting error as : Uncaught TypeError: Cannot read property 'parentNode' of null jQuery中的Ajax调用-未捕获的TypeError无法读取null的属性“错误” - Ajax call in jQuery - uncaught typeerror cannot read property 'error' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM