在angularjs中,在用户上传图像后启用按钮,否则应禁用该按钮

时间:2016-06-05 15:52:31

标签: javascript jquery html angularjs

我想在用户没有上传任何内容时禁用该按钮。用户上传图像后,我想启用该按钮。

我正在尝试使用ng-disabled,但我不确定在用户上传图片后如何将file-uploaded设置为true。

<form action="/api/upload" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <input name="myFile" ng-model="model.file-uploaded" type="file" accept="image/*" class="form-control"/>
        <input name="width" value="{{model.widget.width}}" style="display: none"/>
        <input name="widgetId" value="{{model.widget._id}}" style="display: none"/>
        <input name="pageId" value="{{model.pageId}}" style="display: none"/>
        <input name="websiteId" value="{{model.websiteId}}" style="display: none"/>
        <input name="userId" value="{{model.userId}}" style="display: none"/>
        <button type="submit" class="btn btn-block btn-success" ng-disabled="model.file-uploaded">Upload Image</button>
    </div>
</form>

1 个答案:

答案 0 :(得分:0)

在ng-disable指令中提到方法名称GetFileSize(),并在方法内部根据验证返回true或false。使用jquery代码从GerFileSize()方法中的dom访问元素。