Angularjs autocomplete from $http

前端 未结 5 2144
-上瘾入骨i
-上瘾入骨i 2020-11-29 16:52

I\'m trying to write an autocomplete directive that fetches data from the server using an $http request (without using any external plugins or scripts). Cur

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 17:33

    the easiest way to do that in angular or angularjs without external modules or directives is using list and datalist HTML5. You just get a json and use ng-repeat for feeding the options in datalist. The json you can fetch it from ajax.

    in this example:

    • ctrl.query is the query that you enter when you type.
    • ctrl.msg is the message that is showing in the placeholder
    • ctrl.dataList is the json fetched

    then you can add filters and orderby in the ng-reapet

    !! list and datalist id must have the same name !!

     
    
            
提交回复
热议问题