【发布时间】:2018-02-28 09:03:43
【问题描述】:
在我的 angualr 2 模板表单中,我的输入字段设计方式类似于focus,标签在输入元素顶部动画,focus-out 标签返回到输入元素。similar like this one : [codepen]
我的问题是即使控件具有应该在代码中处理的值,标签也会下降。我不知道如何取输入元素的长度来签入我的component 以保持标签位于顶部。
HTML:
<form #queryForm="ngForm" (ngSubmit)="Search(queryForm.value)">
<div class="form-input">
<div>
<input type="text" class="animate-label"
(focusout)="onLeave(queryForm.value)" name="process" ngModel [ngClass]="{'ontop':hasValue}">
<label>Process</label>
</div>
组件:
export class FormTemplate{
hasValue:boolean;
onLeave(form:any){ //is this the right way to get the value back to component??
console.log(form)
if(form.process.length>0) //syntax??
{
this.hasValue=true;
}
}}
当元素有值时,我将添加ngClass #hasValue 以保持标签在顶部
【问题讨论】:
标签: angular2-forms angular4-forms