如何在角度js中动态更改输入类型 [英] How to change input type dynamically in angular js
问题描述
大家好,
我正在使用angularJS开发MVC。我在其中基于数据库字段从angularjs生成动态HTML控件。喜欢
Hello all,
I am working on MVC with angularJS. In which I am generating dynamic HTML controls from angularjs based on database fields.Like
------------------------------------------------
Lable || Type ||IsRequired || MinLen || MaxLen
------------------------------------------------
Name || text ||Yes || 3 ||10
Mobile|| number||Yes || 10 ||12
DOB ||date ||Yes || -- ||--
------------------------------------------------
我正在使用javascript函数创建控件
And I am creating controls using javascript function using
document.CreateElement(input);
并检查数据库中的值是否为
and checking database values in if else like
if(DatabaseType=="text"){
document.CreateElement(input);
input.type="text";
}else if(DatabaseType=="number"){
document.CreateElement(input);
input.type="number";
}else if(DatabaseType=="date"){
document.CreateElement(input);
input.type="date";
}
并将这些控件附加到div使用
and appending those controls to div using
divId.appendChild(input);
喜欢这个
但是当我的时候值得到改变然后键入日期给我一个问题
它不允许在该文本框中输入文本或数字
我也用$ compile函数然后它也给我一个问题请建议我解决方案
简而言之我想要动态更改输入类型,如日期到文本
但是当我这样做时它不允许。
我是什么尝试过:
like this
But when my values get change then type date gives me a problem
it doesn't allow to enter text or number in that text box
I also used $compile function then also it gives me a problem please suggest me solution
In short I want to change input type dynamically like date to text
but when I do this it doesn't allow.
What I have tried:
if(DatabaseType=="text"){
document.CreateElement(input);
input.type="text";
}else if(DatabaseType=="number"){
document.CreateElement(input);
input.type="number";
}else if(DatabaseType=="date"){
document.CreateElement(input);
input.type="date";
}
divId.appendChild(input);
$compile(divId);
推荐答案
编译功能然后它也给我一个问题请建议我解决方案
简而言之,我想动态改变输入类型,比如日期到文本
但是当我做的时候这是不允许的。
我尝试过:
compile function then also it gives me a problem please suggest me solution
In short I want to change input type dynamically like date to text
but when I do this it doesn't allow.
What I have tried:
if(DatabaseType=="text"){
document.CreateElement(input);
input.type="text";
}else if(DatabaseType=="number"){
document.CreateElement(input);
input.type="number";
}else if(DatabaseType=="date"){
document.CreateElement(input);
input.type="date";
}
divId.appendChild(input);
compile(divId);
compile(divId);
假设您正在获取数据以生成控件,您可以通过angularjs直接动态生成它们。不需要用于createElement的javascript。你可以利用angularjs的力量
Assuming that you are getting data to generate controls, you can dynamically generate them directly through angularjs. No javascript for createElement is required. You can utilize power of angularjs
<table>
<tr ng-repeat="d in data">
<td><input type="d.type" value="d.Lable" minlength="d.minLen" maxlength="d.maxlength"></td>
</tr>
</table>
这篇关于如何在角度js中动态更改输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!