1
我正在尝试构建使用标签和文本输入字段的指令。根据指令模板中不同元素的状态将元素应用于元素
我希望仅当输入字段处于焦点或字段不为空时才显示标签。
这是我现在的代码。我需要把它变成一个指令,以便在其他领域使用它。
<label class="text-field-top-label"></label>
<input type="email"
name="email"
ng-model="user.email"
ng-model-options="{updateOn: 'blur'}"
required
placeholder="Email address"/>
我有搞清楚如何做到这一点,因为我不能看的标签或文本字段麻烦,我不想给他们分配ID,因为我希望把这些元素融入到一个指令。 任何想法都会受到欢迎
你的指令代码在哪里?你不能只使用'ngBlur'(https://docs.angularjs.org/api/ng/directive/ngBlur)和'ngFocus'(https://docs.angularjs.org/api/ng/directive/ngFocus )? –
为什么不在标签中使用'ng-show =“myFunction()”'? – Aer0
ng-show/ng-focus的问题在于我无法访问标签中的输入字段,反之亦然。如果这不是一个指令,我不能遍历dom元素来像他们那样去找他们。 –