我有一個表格並且有上傳圖片。我也有一張已經顯示的照片。我想要做的是當我上傳一張新照片時,它會覆蓋已經顯示的照片。在我的小提琴中,我有一張鴨子圖片,當我上傳新圖片時,它會顯示爲另一張圖片。如何在用戶上傳新圖片時隱藏鴨圖片?如何在angularjs,css中將圖像上傳到現有圖像src
鏈接在我的小提琴:http://jsfiddle.net/DharkRoses/m2qagzzk/6/
示例代碼:
angular.module('test', []);
angular.module('test').controller('UploadCtrl', function ($scope, $timeout) {
$scope.thumbnail = {
dataUrl: []
};
$scope.fileReaderSupported = window.FileReader != null;
$scope.photoChanged = function (files, index) {
if (files != null) {
var file = files[0];
var index = this.$index;
if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
$timeout(function() {
var fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = function (e) {
$timeout(function() {
$scope.thumbnail[index] = {dataUrl: e.target.result};
});
}
http://stackoverflow.com/a/33342251/3030495它會幫助你。 – hurricane