AngularJS-Bootstrap TypeAhead中的错误:TypeError:无法读取未定义的属性“ length”

普拉莫德·卡兰迪卡(Pramod Karandikar)

尝试从AngularUI-Bootstrap实现AngularJS Typeahead时出现以下错误:(我只是在调用一个Servlet,以JSON格式返回结果)

TypeError: Cannot read property 'length' of undefined
    at http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js:3553:24
    at wrappedCallback (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:10930:81)
    at wrappedCallback (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:10930:81)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:11016:26
    at Scope.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:11936:28)
    at Scope.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:11762:31)
    at Scope.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:12042:24)

的HTML

<h4>Users from local service</h4>
    <pre>Model: {{userList | json}}</pre>
    <input type="text" ng-model="userList" placeholder="Users loaded from local database" 
    typeahead="username for username in fetchUsers($viewValue)" 
    typeahead-loading="loadingUsers" class="form-control">
    <i ng-show="loadingUsers" class="glyphicon glyphicon-refresh"></i>

JS

$scope.fetchUsers = function(val) {
        console.log("Entered fetchUsers function");
        $http.get("http://localhost:8080/TestWeb/users", {
            params : {
                username : val
            }
        }).then(function(res) {
            var users = [];
            angular.forEach(res.data, function(item) {
                users.push(item.UserName);
            });
            return users;
        });
    };

Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        UserUtil userUtil = new UserUtil();
        List userList = userUtil.fetchUsers();
        Iterator userIterator = userList.iterator();

        JSONArray users = new JSONArray();


        while(userIterator.hasNext()) {
            UserDetails userDetails = (UserDetails)userIterator.next();

            JSONObject jo =  new JSONObject();
            jo.put("UserID", userDetails.getUserId());
            jo.put("UserName", userDetails.getUserName());
            jo.put("UserDescription", userDetails.getDescription());

            users.add(jo);
        }

        response.setContentType("application/json");
        response.getWriter().write(users.toString());


    }

servlet的响应 在此处输入图片说明

我提到了以下问题:

但是,我仍然无法弄清分辨率。servlet本身的响应是否存在问题?或者是别的什么?

毛里卡

在再次查看代码后,我注意到了什么地方不对,您必须在此处返回$ http promise,return在$ http之前进行通知

$scope.fetchUsers = function(val) {
        console.log("Entered fetchUsers function");
        return $http.get("http://localhost:8080/TestWeb/users", {
            params : {
                username : val
            }
        }).then(function(res) {
            var users = [];
            angular.forEach(res.data, function(item) {
                users.push(item.UserName);
            });
            return users;
        });
    };

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Bootstrap Typeahead w Laravel Uncaught TypeError:无法读取未定义的属性'length'

来自分类Dev

AngularJS Factory $ http无法读取未定义的属性“ length”

来自分类Dev

TypeError:无法读取ReactDataGrid中未定义的属性'length'

来自分类Dev

未捕获的TypeError:无法读取未定义的属性“ length”

来自分类Dev

.ajax JSON TypeError:无法读取未定义的属性“ length”

来自分类Dev

TypeError:无法读取未定义的API TMDB的属性'length'

来自分类Dev

AngularUI-Bootstrap的Typeahead无法读取undefined的length属性

来自分类Dev

JQuery Datatable错误“无法读取未定义的属性'length'”

来自分类Dev

出现此错误:无法读取未定义的属性“ length”

来自分类Dev

npm过时的错误无法读取未定义的属性“ length”

来自分类Dev

JQuery Datatable错误“无法读取未定义的属性'length'”

来自分类Dev

Uncaught TypeError:即使命名正确,也无法读取未定义错误的属性“ length”

来自分类Dev

无法读取未定义的属性“ length”

来自分类Dev

Angularjs / Ionic TypeError:无法读取未定义的属性“ then”

来自分类Dev

AngularJS:TypeError:无法读取未定义的属性“ get”

来自分类Dev

AngularJS:TypeError:无法读取未定义的属性“ then”

来自分类Dev

TypeError:无法读取AngularJS上未定义的属性“ get”

来自分类Dev

AngularJS-TypeError:无法读取未定义的属性“ go”

来自分类Dev

TypeError:无法读取AngularJS上未定义的属性“ get”

来自分类Dev

TypeError:访问购物车时无法读取Commerce JS中未定义的属性“ length”

来自分类Dev

AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

来自分类Dev

AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性“ __id”

来自分类Dev

AngularJS错误:无法读取未定义的属性“ get”

来自分类Dev

AngularJS类型错误:无法读取未定义的属性“ GET()”

来自分类Dev

错误 AngularJs:无法读取未定义的属性“then”

来自分类Dev

Uncaught TypeError:无法读取AngularJS和D3中未定义的属性'arc'

来自分类Dev

Uncaught TypeError:无法读取angularjs代码中未定义的属性“ push”

来自分类Dev

TypeError:无法读取onsen ui,angularjs中未定义的属性'setMainPage'

来自分类Dev

未捕获的TypeError:无法读取angularjs中未定义的属性'indexOf'

Related 相关文章

  1. 1

    Bootstrap Typeahead w Laravel Uncaught TypeError:无法读取未定义的属性'length'

  2. 2

    AngularJS Factory $ http无法读取未定义的属性“ length”

  3. 3

    TypeError:无法读取ReactDataGrid中未定义的属性'length'

  4. 4

    未捕获的TypeError:无法读取未定义的属性“ length”

  5. 5

    .ajax JSON TypeError:无法读取未定义的属性“ length”

  6. 6

    TypeError:无法读取未定义的API TMDB的属性'length'

  7. 7

    AngularUI-Bootstrap的Typeahead无法读取undefined的length属性

  8. 8

    JQuery Datatable错误“无法读取未定义的属性'length'”

  9. 9

    出现此错误:无法读取未定义的属性“ length”

  10. 10

    npm过时的错误无法读取未定义的属性“ length”

  11. 11

    JQuery Datatable错误“无法读取未定义的属性'length'”

  12. 12

    Uncaught TypeError:即使命名正确,也无法读取未定义错误的属性“ length”

  13. 13

    无法读取未定义的属性“ length”

  14. 14

    Angularjs / Ionic TypeError:无法读取未定义的属性“ then”

  15. 15

    AngularJS:TypeError:无法读取未定义的属性“ get”

  16. 16

    AngularJS:TypeError:无法读取未定义的属性“ then”

  17. 17

    TypeError:无法读取AngularJS上未定义的属性“ get”

  18. 18

    AngularJS-TypeError:无法读取未定义的属性“ go”

  19. 19

    TypeError:无法读取AngularJS上未定义的属性“ get”

  20. 20

    TypeError:访问购物车时无法读取Commerce JS中未定义的属性“ length”

  21. 21

    AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

  22. 22

    AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性“ __id”

  23. 23

    AngularJS错误:无法读取未定义的属性“ get”

  24. 24

    AngularJS类型错误:无法读取未定义的属性“ GET()”

  25. 25

    错误 AngularJs:无法读取未定义的属性“then”

  26. 26

    Uncaught TypeError:无法读取AngularJS和D3中未定义的属性'arc'

  27. 27

    Uncaught TypeError:无法读取angularjs代码中未定义的属性“ push”

  28. 28

    TypeError:无法读取onsen ui,angularjs中未定义的属性'setMainPage'

  29. 29

    未捕获的TypeError:无法读取angularjs中未定义的属性'indexOf'

热门标签

归档