我想在取消按钮的点击事件中清除selceted文件名。
<div class="row">
<div class="col-md-5 attribute-labelDiv">
<div ng-hide="isUploadBtn">
<label class="attribute-label">File:</label>
<ul>
<li>{{fileName}}</li>
</ul>
<button title="cancel" class="btn btn-primary" type="reset" value="Reset">Cancel</button>
</div>
</div>
如何在点击取消按钮时清除{{fileName}}。
答案 0 :(得分:1)
使用ng-click指令添加click事件并重置变量名称
<button title="Upload" ng-click="reset()" class="btn btn-primary" type="reset" value="Reset">Cancel</button>
Controller.js
$scope.reset = function(){
$scope.fileName = '';
}
<强>样本强>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.fileName = "sample";
$scope.reset = function(){
$scope.fileName = "";
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<ul>
<li>{{fileName}}</li>
</ul>
<button ng-show="fileName" title="cancel" ng-click="fileName = '';" class="btn btn-primary" type="reset" value="Reset">Cancel</button>
</div>
答案 1 :(得分:1)
你可以像这样使用ng-click
<button title="cancel" ng-click="fileName = ''" class="btn btn-primary" type="reset" value="Reset">Cancel</button>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.fileName = "same text"
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<ul>
<li>{{fileName}}</li>
</ul>
<button ng-init="btnShow = true" title="cancel" ng-show="btnShow" ng-click="fileName = '';btnShow = false;" class="btn btn-primary" type="reset" value="Reset">Cancel</button>
</div>
&#13;