角度形式,嵌套形式,hideExpression不起作用

时间:2016-03-01 18:15:17

标签: angular-formly

在主要字段中写入应该显示子字段组!!!,但只显示兄弟字段!!! '儿童'中的'hideExpression'不起作用??? !!!

在这个例子中,当它们相同时,字段没有嵌套响应它的'hideExpression'和嵌套组。

vm.fields = [
      {
        key: 'sibling',
        type: 'input',
        templateOptions: {
          required: true,
          type: 'text',
          label: 'Sibling'
        },
        hideExpression: '!model.parent.main'
      },
      {
        key: 'parent',
        wrapper: 'panel',
        templateOptions: { label: 'Parent' },
        fieldGroup: [
          {
          key: 'main',
          type: 'input',
          templateOptions: {
            required: true,
            type: 'text',
            label: 'Main'
          }
        },
      {
        key: 'child',
        wrapper: 'panel',
        templateOptions: { label: 'Child' },
        hideExpression: '!model.parent.main', //why it does not work ???!!!!!!!!
        fieldGroup: [
          {
          key: 'child1',
          type: 'input',
          templateOptions: {
            required: true,
            type: 'text',
            label: 'Child1'
          }
        },
        {
          key: 'child2',
          type: 'input',
          templateOptions: {
            required: true,
            type: 'number',
            label: 'Child2'
          }
        }]
      }]
      }
    ];

The nested group remains hidden.

JS Bin here。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

哇,这花了很长时间。

孩子的hideExpression命令基本上可以在以下

中进行
hideExpression: '!model.main'

这可能是 ,因为它无论如何直接指向实际元素的键,而不管父键。当然,这仅适用于这种fieldGroup设置,并且正常!model.parent.main适用于其他sibling元素。这真的很奇怪。

以下是working code

另请查看此link。 这里child2元素在填充child1后启用。这也遵循类似的模式,在fieldGroup中,所有引用都直接由model.keyname_for_the_field