【问题标题】:How to display uploaded image using path in angularJS and MVC?如何使用 angularJS 和 MVC 中的路径显示上传的图像?
【发布时间】:2016-02-10 16:10:11
【问题描述】:

我在特定路径上使用 AngularJs 上传了一张图片。现在我想在该路径的 div 中显示上传的 Single 图片。

请帮我知道如何显示上传的图片?

在我的 AngularJs 控制器中:

$scope.uploadUrl = function () {
    var url = "~/uploads";
}

并且在视野中;

    <div ng-controller="FileUploadController">
    <input type="file" name="myFile" file-upload/>
    <button ng-click="uploadFile()">Upload</button>
    <div>

    <div>
        <img src="http://{{uploadUrl}}"/>
        <img ng-src="http://{{uploadUrl}}"/>
    </div>

我想在点击上传按钮时显示图像,以便在上传后显示图像。

【问题讨论】:

  • 从服务器返回 imagePath 并将 imgpath 分配给图像的src

标签: c# angularjs asp.net-mvc


【解决方案1】:

希望这会有所帮助-

html-

<div ng-app="myApp">
   <div ng-controller="myCtrl">
    <img src="http://{{url}}"/>
    <img ng-src="http://{{url}}"/>
  </div>
 </div>

和控制器-

var myApp = angular.module('myApp', []);

myApp.controller('myCtrl',
   function ($scope) {
    $scope.url = 'cdn1.www.st-hatena.com/users/ho/howdy39/profile.gif';
   }
);

【讨论】:

  • 它在我这边工作,请分享您的视图和控制器代码sn-p。
猜你喜欢
  • 1970-01-01
  • 2019-06-04
  • 2013-04-05
  • 2016-03-09
  • 1970-01-01
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 2013-11-24
相关资源
最近更新 更多