0

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 is " + /*---- how can i print $element's inner html text here --- */)
    console.log("attribute value is " + /*---- how can i read the li element's someAttr value here --- */)
  }
})

This must print this message in the console (when user clicks the mouse),

html content is hello martin
attribute value is hello ricky
1
  • you can use jQuery to do that.. <li ng-click="logMe" someAttr="hello ricky" id="test">hello martin</li> $('#test').html() and $('#test').attr('someAttr'); Commented Jun 20, 2015 at 7:17

1 Answer 1

2

Try like this

HTML

 <li ng-click="logMe($event)" someAttr="hello ricky">hello martin</li>

Controller

$scope.logMe = function(e){
    var value=e.target.attributes.someAttr.value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.