我有两个输入字段,均由同一模板生成。我正在设置这两个内容
...
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/