【问题标题】:function calling giving an, "Cannot read property 'length' of undefined"- AngularJS函数调用给出“无法读取未定义的属性'长度'”-AngularJS
【发布时间】:2014-11-02 21:00:31
【问题描述】:

我正在调用 callKeywords 之类的,

<input type="text" ng-change="keywordsList()" ng-model="searchkeyword.keystring" class="typeahead">

但它会导致 jquery 文件出错。

我在控制器中的功能:

$scope.callKeywords = function() {
    $http.get(myurl).then(calbacksuccess1,calbackerror1);
    function calbacksuccess1(response)
    {
        alert(response);
    }
    function calbackerror1(failure)
    {
        alert(failure);
    }
}

【问题讨论】:

  • 调用服务后是否会调用警报?

标签: javascript jquery angularjs angularjs-scope typeerror


【解决方案1】:

我认为成功和错误回调函数应该附加到 $scope 变量。所以请尝试以下操作:

$scope.callKeywords = function() {
    $http.get(myurl).then(calbacksuccess1,calbackerror1);
};
$scope.calbacksuccess1 = function(response){
    alert(response);
};
$scope.calbackerror1= function(failure){
    alert(failure);
};

这可能是问题所在。

或者

要检查的另一件事是“searchkeyword”是否未定义。检查 $scope.searchkeyword = "";在范围内定义。

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 2017-04-28
    相关资源
    最近更新 更多