本文介绍了角Formly:如何添加类包装DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<formly-form model="vm.model" fields="step.inputs" options="vm.options">
    <div style="text-align:right">
        <button type="submit" wz-next class="btn btn-primary submit-button" ng-disabled="innerForm.$invalid">Næste</button>
    </div>
</formly-form>

使用上面的标记将产生更多的噩不太标准formly形式,但我的问题是基于在 templateOptions 我的字段设置的值,我想成为能够将类添加到formly场DIV。

Using the above markup would generate a more og less standard formly form, but my issue is that based on values set in the templateOptions of my fields, i want to be able to add a class to the formly-field div.

因此​​,一个例子是:

So an example would be:

inputs: [
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatLeft'
        }
    },
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatRight'
        }
    }]

应该产生2 formly字段这样的:

Should generate 2 formly-fields like these:

<div formly-field ng-repeat="field in fields " class="floatLeft ..." ...>...</div>
<div formly-field ng-repeat="field in fields " class="floatRight ..." ...>...</div>

因此​​,类被添加到div,我已经使用包装尝试过,但他们不周围的formly场DIV换行。
而且,由于 step.inputs 是字段的数组,即时通讯不知道如何做到这一点。

So the class gets added to the div, i've tried using wrappers, but they dont wrap around the formly-field div. And since step.inputs is an array of fields, im not sure how to do it.

推荐答案

要类添加到 formly场 DIV ,您只需指定的className 您现场配置的根。所以:

To add classes to the formly-field div, you simply specify a className on the root of your field configuration. So:

inputs: [
    {
        key: 'someKey',
        type: 'input',
        className: 'floatRight',
        templateOptions: {
            label: 'some text'
        }
    },
    {
        key: 'someKey',
        type: 'input',
        className: 'floatRight',
        templateOptions: {
            label: 'some text'
        }
    }
]

这篇关于角Formly:如何添加类包装DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 10:32