我无法使用现有答案找到解决方案,因此我正在创建新帖子。
我想为按钮点击添加验证。
我有这样的场景
我有一个带有两个输入字段和一个上传图像的表单,这里我们有默认图像,用户也有机会上传新图像。 如果用户未上传图像,我们必须在单击提交后显示错误消息。
<div class="form-group">
<img src="{{ImageUrl}}" class="img-responsive m-b-md" />
<button type="button" class="btn btn-primary-outline btn-xs pull-right dash-post-button" aria-label="Post" ng-click="changeImage()">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
<small>change image</small>
</button>
<span ng-show="errImg">please choose the image</span>
</div>
用于图像上传:
$scope.iSupportImageUrl = "images/iceland.jpg";
var setiSupportImageUrl = function (iSupportImgId) {
$scope.iSupportImageUrl = AWSBucketNameConverter.getAWSURL('TELEKHA_ISUPPORT_IMG', iSupportImgId);
};
$scope.changeiSupportImage = function() {
var iSupportImgUpldmodalInstance = $modal.open({
controller: 'EventimageuploadCtrl',
templateUrl: 'views/isupportimageupload.html',
animation: true
});
iSupportImgUpldmodalInstance.result.then(
function (result) {
setiSupportImageUrl(result.fileId);
result.status='a';
result.createdTS='2014-05-04';
result.containerName='TELEKHA_ISUPPORT_IMG';
result.createdById=23;
result.createdName='abc';
$scope.newiSupport.bannerImage=result
},
function () {
}
);
};
最佳答案
你可以这样编写你的函数:
$scope.changeImage = function(imageModel){
if(imageModel){
// upload the image
}
else {
// Show up the error message
}
}
关于javascript - 对 ng-click 指令进行表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46562180/