I'm trying to send a div's id into a function as a parameter when clicked.
But it is not working.
Here's what I have written, please take a look :
<div id="currentId" ng-click="functionCalled(id)">
</div>
I'm trying to send a div's id into a function as a parameter when clicked.
But it is not working.
Here's what I have written, please take a look :
<div id="currentId" ng-click="functionCalled(id)">
</div>
Share
Improve this question
asked May 18, 2017 at 9:55
HarishHarish
1,2738 gold badges24 silver badges47 bronze badges
2
- Is it a string you're passing in as an id? If so have you tried ng-click="functionCalled('currentId')" ? – rrd Commented May 18, 2017 at 9:57
- see this – anoop Commented May 18, 2017 at 10:05
5 Answers
Reset to default 4Edit your code with,
HTML:
<button id="bla" class="button button-light" data-ng-click="functionCalled($event)">
Click Me
</button>
JS:
$scope.functionCalled= function(event){
alert(event.target.id);
}
try to use following method with this object <div id="currentId" ng-click="functionCalled(this.id)">
</div>
The click event function has the event as an argument.
<div id="currentId" ng-click="functionCalled(event)">
Now you can access the properties from the target property in the in the event argument.
function functionCalled(event){
let id = event.target.id;
}
<div id="currentId" ng-click="functionCalled($event)">
</div>
In your controller
functionCalled($event){
//use $event.target.id
}
you can pass this as $event
<div id="currentId" ng-click="functionCalled($event)"></div>
and use this as
e.target.attributes.id.value
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745066074a4609262.html
评论列表(0条)