答案 0 :(得分:1)
更改!myform.username。$ pristine with myform。$在ng-show属性上提交
完整的代码应该是
<form name="myform" ng-submit="formSubmit()" novalidate>
<input ng-model="fields.name.title"
placeholder="Enter your name" name="username" type="text" required>
<span ng-show="myform.username.$error.required && myform.$submitted">Invalid name</span>
<drop-down data="fields.levels" func='levelHandler'></drop-down>
<drop-down data="fields.stages" func='levelHandler'></drop-down>
<drop-down data="fields.colors" func='levelHandler'></drop-down>
<button type="submit">Submit Form</button>
</form>
答案 1 :(得分:1)
这是因为除非您在表单中输入内容(使其变脏),否则您的$pristine
属性为true。
请尝试检查$submitted
。
<span ng-show="myform.username.$error.required && myform.$submitted">Invalid name</span>