我遇到一个可能很简单的问题,但没有找到解决方案。
我需要在更改$ scope.value之后更改ng-class。
<img src="" alt="" class="img-photo-thumb" ng-class="{'show-photo': photoThumb}">
我的angularjs:
angular.module('dh-page')
.controller('MyController', ['$scope', function($scope) {
$scope.initDomEvents = function() {
document.getElementById("fileUploadPhoto").addEventListener('change', handleFileSelect, false);
};
var handleFileSelect = function(event) {
var file = event.target.files[0];
$scope.photo_upload = file;
var render = new FileReader();
render.readAsDataURL(file);
render.onload = function(event) {
var _thumb = document.getElementsByClassName('img-photo-thumb')[0];
_thumb.src = event.target.result;
// Here I change the value but nothing changes in html
$scope.photoThumb = true;
}
};
}]);
是否有可能多次更改ng-class?感谢帮助!
您需要$scope.$apply
为了通知角度更改。
将onload
方法更改为
render.onload = function(event) {
$scope.$apply(function() {
var _thumb = document.getElementsByClassName('img-photo-thumb')[0];
_thumb.src = event.target.result;
// Here I change the value but nothing changes in html
$scope.photoThumb = true;
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句