当我使用$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"}
我的输出:
无需将ng-model绑定到图像,只需将src与图像的绝对路径一起使用即可
<img src ="{{newImg}}" name="img">
无需将ng-model绑定到您的图像,只需使用带有输入标记的image.ng-model的绝对路径的src。
<img ng-src ="newImg" name="newimg" />