我正在嘗試使用圖像窗體API,但是我是geeting錯誤「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>
但我geeting錯誤:
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)
請告訴我這是什麼錯誤?
哪裏'q.userID'從何而來?我敢打賭,這是你的問題。 – Rob 2014-09-05 05:17:57
它應該是'$ scope.image = function(id){'? – 2014-09-05 05:19:53
這是在抱怨'id'沒有被定義。你缺少'id'作爲你的'$ scope.image'函數的參數。 – 2014-09-05 05:23:43