javascript - Access the element inner html and attribute values inside controller function -
html content as,
<div ng-controller="logctrl"> <ul> <li ng-click="logme" someattr="hello ricky">hello martin</li> </ul> </div>
javascript content as,
var app = angular.module('app', []); app.controller('logctrl', function ($scope, $element) { $scope.logme = function(){ console.log("html content " + /*---- how can print $element's inner html text here --- */) console.log("attribute value " + /*---- how can read li element's someattr value here --- */) } })
this must print message in console (when user clicks mouse),
html content hello martin attribute value hello ricky
try
html
<li ng-click="logme($event)" someattr="hello ricky">hello martin</li>
controller
$scope.logme = function(e){ var value=e.target.attributes.someattr.value; }
Comments
Post a Comment