Javascript Can';t读取未定义的属性长度-AngularJS

Javascript Can';t读取未定义的属性长度-AngularJS,javascript,angularjs,angularjs-scope,Javascript,Angularjs,Angularjs Scope,我的一个变量抛出未定义的错误: HTML: 我正在尝试实现typeahead,它工作得很好,但当我将以下代码粘贴到控制器中时(在搜索函数之后/之前): My keystring返回未定义的: $scope.searchkeyword.keystring 子字符串匹配器在我看来是个问题 感谢您的帮助。通过将substringMatcher包装在内部解决了此问题: $.noConflict(); jQuery( document ).ready(function( $ ) { /

我的一个变量抛出未定义的错误:

HTML:

我正在尝试实现typeahead,它工作得很好,但当我将以下代码粘贴到控制器中时(在搜索函数之后/之前):

My keystring返回未定义的:

$scope.searchkeyword.keystring

子字符串匹配器在我看来是个问题


感谢您的帮助。

通过将substringMatcher包装在内部解决了此问题:

$.noConflict();
    jQuery( document ).ready(function( $ ) {
      // My code for substringMatcher
}
来源

$scope.search = function() {
        //alert($scope.searchkeyword.keystring);
     $http.get('myurl'+$scope.searchkeyword.keystring).then(sucesscalback,errorcalback);
        function sucesscalback(response)
        {
            //some code
        }
        function errorcalback(failure)
        {
            //some code
        }
$scope.substringMatcher = function(strs) {
        return function findMatches(q, cb) {
            var matches, substrRegex;
            matches = [];
            substrRegex = new RegExp(q, 'i');
            $.each(strs, function(i, str) {
                if (substrRegex.test(str)) {
                    matches.push({ value: str });
                }
            });
            cb(matches);
        };
    };

           $scope.states = ['Connecticut', 'Delaware', 'Wisconsin', 'Wyoming'];
           var myTypeahead =  $('.typeahead').typeahead({
                hint: true,
                highlight: true,
                minLength: 1,
              },
              {
                name: 'states',
                displayKey: 'value',
                source: $scope.substringMatcher($scope.states)
              });
$.noConflict();
    jQuery( document ).ready(function( $ ) {
      // My code for substringMatcher
}