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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -