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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -