我正在从restful中获得json响应中的图像,我必须使用angularjs在html中使用该图像。
我不知道我怎么用angularJs来使用那个图像
如果我尝试像这样的"http:/api/image/id",其中id是"userID"。但是当我用angularjs编写代码时,我没有得到任何响应,我试图使用断点来调试代码,但是它没有进入函数中
JS代码
QAApp.controller('imgCtrl', function ($scope, $http) {
$scope.image = function (id) {
var request = $http({
method: 'GET',
url: server + 'api/image/' + id,
});
request.success(function(data, status, headers, config) {
console.log(data);
});
}
});
HTML代码
<div class="artst-pic pull-left" ng-controller="imgCtrl">
<img ng-show = "{{image(q.userID)}}" alt="" class="img-responsive" />K
</div>
请告诉我怎么用这个。
发布于 2014-09-02 08:51:21
据我所知,API直接向您发送图像,而不是任何JSON。
然后显示它,就像显示任何图像一样(不需要ajax):
JS
$scope.image = function (id) {
return server + 'api/image/' + id;
};
HTML
<img ng-src="{{image(q.userID)}}"/>
发布于 2014-09-01 15:30:28
Javascript
QAApp.controller('imgCtrl', function ($scope, $http) {
$scope.image = function (id) {
$http({
method: 'GET',
url: server + 'api/image/' + id,
}).then(function(data){
$scope.imageUrl= data; // if you sure what data is you URL
})
}
});
HTML
<div class="artst-pic pull-left" ng-controller="imgCtrl">
<img ng-src="{{imageUrl}}" ng-init="image(q.userID)" alt="" class="img-responsive" />K
</div>
发布于 2014-09-01 17:48:26
Apache源代码有一个使用angular.js引入图像源的示例:http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp?annotate=1621546 (第126行,文件底部是JavaScript )。
https://stackoverflow.com/questions/25608978
复制相似问题