我是AngularJs的新手..从后端我得到了这样的数组。
基于" fieldType"不同类型的元素应附加到" div"标签。请帮我。
forms.js
angular.module('forms', [])
.controller('formCtrl', ["$http","$scope",
function($http,$scope) {
$scope.baseUrl= "http://localhost:3000";
$scope.formName = "";
$scope.formDescription = "";
$scope.elements = [{
"filedType" : "text",
"displayName" : "Name",
"hintText" : "Enter your name"
},
{
"fieldType" : "radio",
"displayName" : "Gender",
"valueList" : ["Male","Femal"]
}
]
}]);
forms.html
<div id="form">
<p ng-repeat=" element in elements">
<p ng-if="element.fieldType=='text' "> Textbox </p>
</p>
</div>
答案 0 :(得分:2)
在html中使用以下代码
<p ng-repeat=" element in elements">
<p ng-if="element.fieldType='radioGroup'">
radioGroup
</p>
<p ng-if="element.fieldType='textBox'">
textBox
</p>
</p>
并定义这样的元素
$scope.elements = [{
"filedType" : "textBox",
"displayName" : "Name",
"hintText" : "Enter your name"
},
{
"fieldType" : "radioGroup",
"displayName" : "Gender",
"valueList" : ["Male","Femal"]
}
];