javascript - Angular-formly:为什么指令的行为与类型不同?

标签 javascript angularjs angular-formly

我有两个输入字段,均由同一模板生成。我正在设置这两个内容

...    
templateOptions: {
  ...
  required: true
}

使用 formlyConfig.setType 注册一个输入字段 另一个使用指令。我创建了一个JS Bin here .

只有第一个获得了所需的属性,第二个则没有。在 docs对于自定义模板( Controller 选项),它说:

Provides you the ability to add custom behavior to the type without having to make an entire directive (you can make a directive instead if you wish).

我做错了什么?

最佳答案

第二个示例中的问题是,当 Angular-formly 使用模板处理选项时,所有 Angular-formly 看到的是: <plain-text>对于模板。因此,它不知道将 required 放置在哪个元素中。属性上。 Angular-formly 只会将类似的属性附加到具有 ng-model 的元素上因为这些是该属性唯一有意义的元素。

同样,这里的关键是 Angular-formly 在处理模板时(在编译之前)看到的内容。该指令编译成什么并不重要。所以是的,您可以使用自己的指令,但如果您想利用 Angular-formly 的功能,则需要利用 ng-model Controller (如 this example 中使用的指令)。

祝你好运!

关于javascript - Angular-formly:为什么指令的行为与类型不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34660454/

相关文章:

JavaScript - 事件 relatedTarget 不适用于 onClick

javascript - AngularJS:为什么我的指令不能使用 $scope?

javascript - Angular formly - 从包装器中的字段获取模型

javascript - 使用 Angular Formly 时,表单提交中不包含空字段

javascript - 哪张图表适合员工了解 12 个月的可交付成果?

javascript - 如何将 polyfill 转移到 iframe?

javascript - 工作灯 6.2 : Unable to add multiple js files in windows phone 8 environment

javascript - 我是否正确绑定(bind)了 AngularFire(Angular+FireBase)?

javascript - 将特定 div 中的所有内容保存为图像

angularjs - 如何在新行上打印输出?