Created
February 17, 2017 04:12
-
-
Save weihanchen/b30cae8cfac1595efa0ff8ad01224a34 to your computer and use it in GitHub Desktop.
Angular input select all on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function() { | |
angular.module('notes') | |
.controller('selectAllOnClickController', [selectAllOnClickController]) | |
function selectAllOnClickController() { | |
var self = this; | |
self.text = "Click me to select all" | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function() { | |
angular.module('note') | |
.directive('selectAllOnClick', selectAllOnClick) | |
function selectAllOnClick() { | |
return { | |
restrict: 'A', | |
controller: ['$element', selectAllOnClickController], | |
controllerAs: 'selectAllOnClickCtrl', | |
bindToController: true | |
} | |
function selectAllOnClickController($element) { | |
} | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function() { | |
angular.module('note') | |
.directive('selectAllOnClick', selectAllOnClick) | |
function selectAllOnClick() { | |
return { | |
restrict: 'A', | |
controller: ['$element', selectAllOnClickController], | |
controllerAs: 'selectAllOnClickCtrl', | |
bindToController: true | |
} | |
function selectAllOnClickController($element) { | |
$element.on('click', function() { | |
var isInputSelected = $element[0].selectionEnd - $element[0].selectionStart != 0; | |
if (!isInputSelected) { | |
$element.select(); | |
} | |
}) | |
} | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form class="form-inline"> | |
<div class="form-group"> | |
<input type="text" class="form-control" ng-model="selectAllOnClickCtrl.text" placeholder="Please input some text and test select all operation..." select-all-on-click /> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment