我有一个简单的表单,有两个文本输入,如下所示:
<form>
// this is visible in mobile view
<input id="mobileView" type="email" required ng-model="myValue" />
// this is visible on desktop view
<input id="desktopView" type="email" required ng-model="myValue" />
</form>
我的问题是这样做是否违反了角形验证?因为两个输入都在DOM中,在一个视图中,其中一个具有价值,而在另一个视图中,它没有任何价值。这会破坏角度的验证吗?
答案 0 :(得分:1)
您的代码是正确的并使用ng - 如果它处理DOM元素。
<form>
// this is visible in mobile view
<input id="mobileView" type="email" ng-if="condition for mobile view" required ng-model="myValue" />
// this is visible on desktop view
<input id="desktopView" type="email" ng-if="condition for desktop view" required ng-model="myValue" />
</form>