我驗證&提交使用angularjs一個簡單的表格,表格似乎做一些初步的驗證,但提交按鈕不記錄或執行定義它的角功能。我究竟做錯了什麼?angularjs提交按鈕不工作
主要app.js
var quora=angular.module("quora-app",['q-controller-1','ngRoute']);
quora.config(function ($routeProvider) {
$routeProvider
.when('/edit',{
templateUrl:'../resources/views/forms/edit.blade.php',
controller:'q-master-1'
});
});
控制器
angular.module("q-controller-1",[])
.controller("q-master-1",['$scope',function ($scope) {
$scope.update=function(value,text) {
$scope.id=value;
$scope.putText=text;
}
$scope.validate=function(updateInfo) {
console.log(updateInfo);
if($scope.update.$valid) {
$scope.test1=$scope.id
$scope.test2=$scope.updateInfo.qText
}
else
console.log("no")
}
}]);
edit.blade.php
<form name="update" method="POST" action="edit.blade.php" ng-submit="validate(updateInfo);" onsubmit="return false;" >
<b ng-show="update.question.$dirty && update.question.$error.required">Invalid</b>
<input type="text" name="question" ng-required="true" ng-minlength="3" ng-value="putText" ng-model="updateInfo.qText">
<input type="submit" name="submit" value="Update" ng-show="update.$valid">
</form>
文件,其中執行發起
@{{ test1 }}
@{{ test2 }}
@section('list-questions-answers')
<div ng-view></div>
<ul>
@foreach($listQuestionsAnswers as $q)
<li>
<a href="{{url('/questions/'.$q->question_id)}}">{{ $q->question }}</a>
Options: <a href="#edit" ng-click="update({{ $q->question_id }},'{{ $q->question }}')">Edit</a>
</li>
@foreach($q->answers as $a)
<ul>
<li>{{ $a->answer }}</li>
</ul>
@endforeach
@endforeach
</ul>
@endsection
的ng-view
正在加載,但提交按鈕不能正常工作或記錄任何東西!
嘗試刪除onsumbit屬性! –
然後它會像一個正常的形式提交,這是沒用的! –
你可以做一件事不要原生的方法。取而代之的是刪除ng-submit和提交,action post以及所有這些,只需在提交按鈕中添加ng-click並使用ng-disabled來禁用提交按鈕,直到表單有效,就像你現在正在做的那樣 –