ngTagsInput / auto-complete(AngularJS)

时间:2016-07-05 08:58:02

标签: angularjs

我正在尝试使用自动完成显示标记输入字段,因此,如果用户在输入字段中输入一些文本,则可用标记在下拉列表中显示为建议。到目前为止一切正常:

<body ng-app="plunker" ng-controller="MainCtrl">
    <tags-input ng-model="tags" add-on-paste="true">
        <auto-complete source="loadTags($query)"></auto-complete>
    </tags-input>
    <p>Model: {{tags}}</p>
</body>

AngularJS代码:

var app = angular.module('plunker', ['ngTagsInput']);

    app.controller('MainCtrl', function($scope, $http) {
        $scope.loadTags = function(query) {
            return $http.get(Routing.generate('my_route_to_json_data'));
        }
    });

以下是工作结果: enter image description here

问题是当我尝试添加maxResultsToShow="4"minLength="1"属性时,它们不起作用,我仍然得到相同的结果。

<body ng-app="plunker" ng-controller="MainCtrl">
    <tags-input ng-model="tags" add-on-paste="true">
            <auto-complete maxResultsToShow="4" loadOnEmpty=true minLength="1" source="loadTags($query)"></auto-complete>
    </tags-input>
    <p>Model: {{tags}}</p>
</body>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

<auto-complete max-results-to-show="4" load-on-empty="true" min-length="1" source="loadTags($query)">

在angular中,你必须在html标签中使用dash-case,在JS代码中使用camelCase,它们会自动转换。

相关问题