当图像的url没有改变但是其内容有?时,如何强制angularjs重新加载具有ng-src属性的图像?
<div ng-controller='ctrl'>
<img ng-src="{{urlprofilephoto}}">
</div>
Run Code Online (Sandbox Code Playgroud)
执行文件上载的uploadReplace服务正在替换图像的内容,而不是url.
app.factory('R4aFact', ['$http', '$q', '$route', '$window', '$rootScope',
function($http, $q, $route, $window, $rootScope) {
return {
uploadReplace: function(imgfile, profileid) {
var xhr = new XMLHttpRequest(),
fd = new FormData(),
d = $q.defer();
fd.append('profileid', profileid);
fd.append('filedata', imgfile);
xhr.onload = function(ev) {
var data = JSON.parse(this.responseText);
$rootScope.$apply(function(){
if (data.status == 'OK') {
d.resolve(data);
} else {
d.reject(data);
}
});
}
xhr.open('post', '/profile/replacePhoto', true)
xhr.send(fd)
return d.promise;
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
当uploadReplace返回时,我不知道如何强制图像重新加载
app.controller('ctrl', ['$scope', 'R4aFact', function($scope, R4aFact){
$scope.clickReplace = …Run Code Online (Sandbox Code Playgroud) angularjs ×1