【问题标题】:How to write formly template to set ng-tags-input's auto-complete source?如何编写模板来设置 ng-tags-input 自动完成源?
【发布时间】:2015-10-26 23:11:14
【问题描述】:

我正在尝试编写一个自定义的正式模板来使用 ng-tags-input:

angular.module('myMod').run(function(formlyConfig) {
    formlyConfig.setType({
        name:'tag',
        template:"<label class='control-label' ng-if='to.label'>{{to.label}}</label>" +
        "<tags-input ng-model='model[options.key]' ng-attr-placeholder='{{to.placeholder}}'>" +
        "<auto-complete source='{{to.tags}}'></auto-complete></tags-input>"
                        ^^^^^^^^^^^^^^^^^^^
    });
})

其中to.tags指的是formly模板的templateOptions:

            templateOptions: {
                tags: 'dataModel.getProductTags()'

在这种情况下使用双括号会导致 $parse 错误。我怎样才能从to.tags的内容中间接填充那个source属性?

我也试过ng-attr-source='to.tags',但没有成功。

我怀疑我只是没有想到一些显而易见的事情。如果简单且明智,请附上相关参考资料。

【问题讨论】:

    标签: angularjs ng-tags-input angular-formly


    【解决方案1】:

    解决方案是将函数而不是函数的名称放在 templateOptions 中,如下所示:

                templateOptions: {
                    tags: dataModel.getProductTags
    

    在模板中,调用它:

    <auto-complete source='to.tags()'>
    

    这要求函数本身必须可以从表单模板访问,但在我的情况下这不是问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多