Is it possible to hit the escape key anywhere on the page without focusing on any element like a button or input? This approach fails:
$(document).keyup(function(e) {
if (e.keyCode === 27) {
$location.path("/");
}
});
However, this method works:
$scope.cancelEdit = function() {
$location.path('/');
}
Here's the HTML code for the working solution:
<button ng-click="cancelEdit()" type="button" class="btn btn-default">Cancel</button>
UPDATE:
1. The following methods also do not work:
$document.on('keyup', function(e) {.....
$document.bind('keyup', function(e) {....
2. Below is the complete HTML structure:
<div class="edit jumbotron">
<i id="loader" class="glyphicon glyphicon-refresh"></i>
<form name="editForm" class="form-horizontal" ng-submit="saveEdit()">
<div class="panel panel-info">
<div class="panel-heading">Edit Site Actions</div>
<table class="edit_table table table-striped">
<thead>
<tr>
<th class="action_name_cell">Action</th>
<th class="float_cell">Warning Threshold</th>
<th class="float_cell">Error Threshold</th>
<th class="toggle_cell">Enabled</th>
</tr>
</thead>
<tbody>
<tr class="data_row" ng-repeat="row in get_edit_rows()">
<td class="action_name_cell">{{row.action_name}}</td>
<td class="float_cell">
<div class="form-group">
<div class="col-sm-8">
<input type="number" class="form-control" ng-model="row.warning"
name="{{row.threshold_id}}_warning"
placeholder="10.0" ng-value="row.warning"
ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/"
step="0.1" required />
</div>
</div>
</td>
<td class="float_cell">
<div class="form-group">
<div class="col-sm-8">
<input type="number" class="form-control" ng-model="row.error"
name="{{row.threshold_id}}_error"
placeholder="10.0" ng-value="row.error"
ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/"
step="0.1" required />
</div>
</div>
</td>
<td class="toggle_cell">
<label></label>
<toggle ng-model="row.enabled" name="{{row.threshold_id}}_enabled"
ng-true-value="'on'" ng-false-value="'off'"></toggle>
</td>
</tr>
</tbody>
</table>
</div>
<!-- END panel / panel-info -->
<!-- Buttons -->
<div class="base_button_wrapper">
<button type="submit" class="btn btn-success">Save</button>
<button ng-click="cancelEdit()" type="button" class="btn btn-default">Cancel</button>
</div>
</form>
</div>