逻辑:
if(condition)
Use first `<form ng-submit="action1">`
else
Use second `<form ng-submit="action2">`
PHP方法中的逻辑:
<?php
if(condition){
echo "<form action='action1.php' >";
}
else{
echo "<form action='action2.php' >";
}
echo "....many many many inputs here...";
echo "</form>";
?>
我想写的是这样的:(我使用的是AngularJs)
<form ng-submit="action1" ng-if="condition1"> ---> First condition
<form ng-submit="action2" ng-if="condition2"> ---> Second condition if first condition fails
....Many many many inputs
</form>
但当然我可以简单地写下这样的东西:(在屁股上会很痛苦)
<div ng-if="condition1"> ---> First condition
<form ng-submit="action1" >
....Many many many inputs
</form>
</div>
<div ng-if="condition2"> ---> Second condition if first condition fails
<form ng-submit="action2" >
....Same inputs as in the first div
</form>
</div>
我的问题是,是否可以在ng-if
代码中使用ng-disabled
(我也尝试了<form>
)?
如果我要做的唯一更改是开始inputs
标记,我试图避免的是重新编码form
内的所有<form>
。
我已经找到了答案但没有找到任何答案,唯一剩下的就是确认和询问。
答案 0 :(得分:1)
如果区别仅是您要在提交时调用的函数,则可以在函数本身中进行测试。
<form ng-submit="mySubmit" >
...Many many many inputs
</form>
控制器
$scope.mySubmit = function(){
if($scope.condition1){
// call the function 1
action1();
}else{
// call the function 2
action2();
}
}
答案 1 :(得分:0)