gpt4 book ai didi

javascript - 将 ng-class 属性放入 Angular-formly 字段

转载 作者:行者123 更新时间:2023-12-03 05:43:31 25 4
gpt4 key购买 nike

大家好,我正在尝试使用 Angular-formly 创建一个表单,我有这样的定义:

{
"options": {
"data": {
"someData": 6
}
},
"fieldGroup": [
{
"className": "ctnStepper",
"key": "customField ",
"type": "form-section"
},
{
"className": "ctnChamp",
"key": "inputTest",
"type": "input"
}
]
}

我想将 ng-class 属性放在 inputTest 字段上,这样之后,生成的表单将产生如下所示的内容:

<input ng-class="{ 'myClass': model. Something != somethingElse }">

我尝试对 ngModelElAttrs 执行此操作,但它很难理解,我被困在这里。预先感谢您的回答。

奥古斯丁

最佳答案

我已经为div分配了类,您可以根据您的要求使用。

ng-class="{'alert-danger':x.key=='customField', 'alert-info':x.key=='inputTest'}"

function myCtrl($scope) {


$scope.myData={
"options": {
"data": {
"someData": 6
}
},
"fieldGroup": [
{
"className": "ctnStepper",
"key": "customField",
"type": "form-section"
},
{
"className": "ctnChamp",
"key": "inputTest",
"type": "input"
}
]
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<div ng-app ng-controller="myCtrl">
<div ng-repeat="x in myData.fieldGroup">
<div class="alert" ng-class="{'alert-danger':x.key=='customField', 'alert-info':x.key=='inputTest'}">{{x.className}}</div>
</div>
</div>

关于javascript - 将 ng-class 属性放入 Angular-formly 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40421763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com