Angular JS - “错误:[$ interpolate:interr]无法插补:”?

时间:2014-09-05 05:13:22

标签: angularjs

我正在尝试使用图像格式API,但我正在设置错误" Angular JS - “错误:[$ interpolate:interr]无法插补:”"。

这是我的代码:

服务Js代码:

    .factory('Comment', function($http) {

        return {
        image : function(id){
                        return $http.get(server + 'api/image/' + id); 
                    }
        }
}

控制器代码:

$scope.image = function () {
                Comment.image(id)
                .success(function(data){});
              }

HTML代码:

<div class="container"  ng-controller="mainController" >
<div class="row" ng-repeat="q in qa.data" >
    <div class="col-md-12 col-xs-12 col.sm.12" >
        <div class="artist-data pull-left" style = "background-color:#BEB7B7;">
            <!-- Div for user image -->
            <div class="artst-pic pull-left" >
                <img width = 100px; height:60px; ng-src="{{image(q.userID)}}"  alt="" class="img-responsive"/>
            </div>

但我正在纠错:

Error: [$interpolate:interr] http://errors.angularjs.org/1.2.1/$interpolate/interr?p0=%7B%7Bimage(q.userID)%7D%7D&p1=ReferenceError%3A%20id%20is%20not%20defined
    at Error (native)
    at file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:6:447
    at q (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:73:428)
    at pre (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:57:412)
    at B (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:49:261)
    at h (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:43:24)
    at h (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:43:41)
    at h (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:43:41)
    at h (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:43:41)
    at h (file:///C:/xampp/htdocs/test_QA/vender/angular.min.js:43:41)

请告诉我这是什么错误?

1 个答案:

答案 0 :(得分:1)

您的image函数声明应如下所示:

$scope.image = function (id) {
    Comment.image(id)
           .success(function (data) {});
};