【问题标题】:ng-tags-input autocomplete should generate tags through static array of objectsng-tags-input 自动完成应该通过对象的静态数组生成标签
【发布时间】:2017-01-24 07:33:36
【问题描述】:

我在 AngularJS 1 中使用 ng-tags-input 作为国家列表。我不想使用 $http.get() 来获取标签。我有一个要在标签中使用的静态对象数组。

【问题讨论】:

    标签: angularjs ng-tags-input


    【解决方案1】:

    在你的加载函数中使用promise angular service:

    $q(function (resolve, reject) {
       resolve($scope.myArray);
    }
    

    这个:

    <auto-complete source="loadTags()"></auto-complete>
    

    应该是:

    $scope.loadTags = function () {
        return $q(function (resolve, reject) {
           resolve($scope.myArray);
        };
    };
    

    $q 创建一个 Promise 并且你的插件需要它。

    别忘了在你的依赖中包含$q

    【讨论】:

    • 如何显示 $scope.myArray 特定属性以自动完成标签?
    • @AhmerKhan 使用我上面建议的方法。它返回你的数组。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多