如何显示来自所选 ID 的图像
How to display image from selected id
我试图在使用 $routeParams.id
获取 ID 时显示用户的信息,我已经仅使用文本显示了用户的信息,但是如何使用 [=14= 显示用户的图像]?
在我的控制器中,我这样做是为了获得选定的用户。
.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 绑定到您的图像,只需使用带有图像绝对路径的 src..ng-model 仅使用输入标签。
<img ng-src ="newImg" name="newimg" />
我试图在使用 $routeParams.id
获取 ID 时显示用户的信息,我已经仅使用文本显示了用户的信息,但是如何使用 [=14= 显示用户的图像]?
在我的控制器中,我这样做是为了获得选定的用户。
.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 绑定到您的图像,只需使用带有图像绝对路径的 src..ng-model 仅使用输入标签。
<img ng-src ="newImg" name="newimg" />