Javascript 角度形式:如果从下拉框中选择了选项,则创建一个必填字段

Javascript 角度形式:如果从下拉框中选择了选项,则创建一个必填字段,javascript,angularjs,angular-formly,Javascript,Angularjs,Angular Formly,如果从相应的下拉框中选择了一个选项,我希望输入一个必填字段。一旦从下拉框中选择了一个选项,My 2字段将被复制,因此用户不限于单个选项。所以如果选择了exportSupplier,则agreementReference变为必填项。但是,如果有多个exportSupplier,且其中至少一个未被选择,则表单将协议参考字段视为非必需 如果选择了相应的exportSupplier,如何制作相应的协议参考字段required vm.exportSuppliers = [{ exportSuppl

如果从相应的下拉框中选择了一个选项,我希望输入一个必填字段。一旦从下拉框中选择了一个选项,My 2字段将被复制,因此用户不限于单个选项。所以如果选择了
exportSupplier
,则
agreementReference
变为
必填项
。但是,如果有多个
exportSupplier
,且其中至少一个未被选择,则表单将
协议参考
字段视为
非必需

如果选择了相应的
exportSupplier
,如何制作相应的
协议参考
字段
required

    vm.exportSuppliers = [{ exportSupplier: '', agreementReference: '' }];

    vm.exportSupplierFields = [
        {
            fieldGroup: [
                {
                    className: 'col-xs-6',
                    key: 'exportSupplier',
                    type: 'select2',
                    templateOptions: {
                        label: 'Export Supplier',
                        required: false,
                        options: [],
                        onChange: function() {
                            vm.addExportSupplier();
                        }
                    }
                },
                {
                    className: 'col-xs-5',
                    key: 'agreementReference',
                    type: 'input',
                    templateOptions: {
                        label: 'Agreement Reference',
                        onChange: function() {
                            vm.addExportSupplier();
                        }
                    },
                    expressionProperties: {
                        'templateOptions.required': '!!model["exportSupplier"]'
                    }
                }
            ]
        }
    ];

    vm.addExportSupplier = function() {
        if (vm.exportSuppliers[vm.exportSuppliers.length - 1].exportSupplier || vm.exportSuppliers[vm.exportSuppliers.length - 1].agreementReference) {
            vm.exportSuppliers.push({ exportSupplier: '', agreementReference: '' });
        }
    };
我的HTML

<div ng-repeat="supplier in vm.exportSuppliers" class="row">
    <formly-form model="supplier" fields="vm.exportSupplierFields"
        form="vm.informationExportSupplier.form" index="$index">
    </formly-form>
</div>

我尝试了不同的变体,将$index添加到“templateOptions.required”字段中,但没有成功

我尝试了不同的变体,将$index添加到“templateOptions.required”字段中,但没有成功


从文档中:

选项
表单的选项

数据
这是一个物体。你想放什么就放什么


我不确定如何使用它将所需值设置为expressionProperties中的相应字段。
<div ng-repeat="supplier in vm.exportSuppliers" ng-init="outsideIndex = $index">
    <formly-form model="supplier" fields="vm.exportSupplierFields"
        form="vm.informationExportSupplier.form"  ̶i̶n̶d̶e̶x̶"̶$̶i̶n̶d̶e̶x̶"̶
        options="{data: {outsideIndex: outsideIndex}}">
    </formly-form>
</div>