将ng-class属性放入angular-formly字段

时间:2016-11-04 11:39:50

标签: javascript angularjs angular-formly

大家好我正在尝试用角度形式创建一个表单我有这个定义:

    String dbURl = "jdbc:sqlserver://localhost:1433;DatabaseName=db";
    String userName = "u";
    String password = "P";
    new sam(dbURl, userName, password).createSQLFile();

}

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

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

我试着把这个坦克带到ngModelElAttrs,但是很难理解,我被困在这里。提前感谢您的回答。

奥古斯丁

1 个答案:

答案 0 :(得分:1)

我已将课程分配给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>