寫了一個圖片上傳的指令upload.directive('uploadFile',function(){ return {
restrict: 'A',
link: function(scope, element, attr) {
element.bind('change',function(event){ var file = this.files[0]; var name = this.name;
scope.onchange(name, file);
});
}
};
});<div class="upload">
<div ng-show="!isUp">
<input type="file" name="myPic" upload-file id=""/>
</div>
<div ng-click="delPic()" ng-show="isUp">
<span>刪除</span>
<img src="{{imgurl}}"/>
</div></div>當我選擇a圖上傳以后,如何清空input的值呢?因為如果不清空input的值,我刪除a圖片以后($scope.isUp=false; $scope.imgurl=''),再選擇a圖就沒效果了,因為input綁定的時change事件,input的值不發(fā)生改變的話是不會調用$sope.onchange的
angularjs 自定義指令時數(shù)據(jù)無法更新
慕容708150
2018-08-11 10:09:20