如何显示所选ID的图像

问题描述 投票:0回答:2

当我使用$routeParams.id获取id时,我正在尝试显示用户的信息,我已经仅使用文本显示了用户的信息但是如何使用img src显示用户的图像?

在我的控制器中,我这样做是为了获得所选用户。

.controller('editbloodrequestCtrl', function($scope,$routeParams, Bloodrequest) {
var app = this;
     Bloodrequest.getBloodrequest($routeParams.id).then(function(data) {
        if (data.data.success) {              
            $scope.newLastname = data.data.bloodrequest.lastname; 
            $scope.newFirstname = data.data.bloodrequest.firstname; 
            $scope.newImg = data.data.bloodrequest.img; 
            app.currentUser = data.data.bloodrequest._id; 
        } else {
            app.errorMsg = data.data.message; 
        }
    });
});

现在我收到了用户信息,我在前端显示了这一点

<label>Lastname:</label>
<input class="form-control" type="text" name="lastname" ng-model="newLastname">

<label>Firstname:</label>
<input class="form-control" type="text" name="firstname" ng-model="newFirstname">

<label>Image:</label>
<img src ="" name="img" ng-model="newImg"> //how can I display the image here?

样本文件:

 {firstname:"James",lastname:"Reid",img:"random.jpg"}

我的输出:

enter image description here

node.js angularjs mongodb mean-stack
2个回答
1
投票

无需将ng-model绑定到图像,只需将src与图像的绝对路径一起使用即可

<img src ="{{newImg}}" name="img">

0
投票

无需将ng-model绑定到您的图像,只需使用带有输入标记的image.ng-model的绝对路径的src。

<img ng-src ="newImg" name="newimg" />
© www.soinside.com 2019 - 2024. All rights reserved.