I have an anchor tag which when clicked should change it's text in the ng-click function. Can someone pleas help me out on this? Below is the code:
<div ng-app="Test">
<div ng-controller="Foo">
<a class="anchClass" ng-click="hi($event)">click me</a>
</div>
angular.module('Test',[]).controller('Foo', function ($scope, $element) {
$scope.hi = function (e) {
var elem = angular.element(e.srcElement);
elem.val("Search");
}
})
Use $event.currentTarget to change current element's text
angular.module('Test', []).controller('Foo', function($scope, $element) { $scope.hi = function(e) { e.currentTarget.text = "Search"; } })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="Test"> <div ng-controller="Foo"> <a class="anchClass" ng-click="hi($event)">click me</a> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.