在我的表单中,我有来自 json 的标签和输入值,如下所示
"attribut1":{
"name":"attrib1",
"type":"text"
},
"attribut2":{
"name":"attrib2",
"type":"number"
}
因此,对于标签,我只是输入 value.name,它给了我名称,但是当我放入输入 value.type 的类型时,它不起作用
<label for="key">{{value.name}}</label>
<input type="value.type" class="form-control form-control-rounded" id="key" placeholder="">
我不知道如何将类型设置为变量,我需要一些帮助
最佳答案
使用双大括号表示法来设置属性。
var myApp = angular.module('DemoApp', []);
myApp.controller('DemoCtrl', function() {
this.inputs = {
"attribut1": {
"name": "attrib1",
"type": "text"
},
"attribut2": {
"name": "attrib2",
"type": "number"
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="DemoApp" ng-controller="DemoCtrl as ctrl">
<ng-container ng-repeat="a in ctrl.inputs">
<label>{{a.name}}</label>
<input type="{{a.type}}">
</ng-container>
</div>
关于javascript - 如何在输入类型中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51056017/