還有就是要找到一種方法來驗證數據尚未 (可能是jqueryvalidation),但可以是一個起點。 我覺得沒有辦法讓遊戲的價值$有效 所以我認爲
var app = angular.module("myApp", [])
app.controller("FormsCtrl", function($scope) {
//console.log($scope);
// $scope.items = ['Games', 'Music', 'Videos'];
$scope.$on('someEvent',function(e,a){
console.log(a);
})
});
app.directive("myform", function() {
return {
restrict: "A",
link:function(scope,element,attrs){
element.bind('submit',function(e){
var isValid = false; // TO DO :)
scope.$emit('someEvent', [attrs.fname,isValid]);
});
}
}
});
<div ng-controller="FormsCtrl">
<div ng-switch on="page">
<div ng-switch-when="Games">
<div ng-include="'Games.html'"></div>
</div>
<div ng-switch-when="Music">
<div ng-include="'Music.html'"></div>
</div>
<div ng-switch-when="Videos">
<div ng-include="'Videos.html'"></div>
</div>
</div>
</div>
<form name="games" class="simple-form" myform fname="games">
<input type="text" ng-model="prefix.games.name" name="uName" required /><br>
</form>
編輯 更聰明更快捷的方法:)
app.controller("FormsCtrl", function($scope) {
$scope.mySubmit = function(isValid){
console.log(isValid);
}
});
<form name="games" class="simple-form" ng-submit="mySubmit(games.$valid)">
<input type="text" ng-model="prefix.games.name" name="uName" required /><br>
</form>
你想使用獨特的表單還是需要在每種表單中進行驗證?我的意思是你必須驗證比音樂更好的遊戲...... – Whisher
我不認爲你的問題很清楚你想要達到的目標。請考慮修改。 – eddiec
我已經修改了描述。當我點擊提交時,我需要驗證所有3種形式,並且如果可能,請更改左側導航文本顏色(遊戲,音樂..),以突出顯示錶單未填充/無效。 – user1184100