Maybe the title isn't perfect - but I'm explaining shortly:
In my HTML I'm using ng-click directive:
(I'm using few ng-clicks directives within my HTML code with different parameters (like 'main', 'action', 'more', etc..)
ng-click="clickMe('main')"
I have a controller to get the id - 'main':
.controller('clickCtrl', ['$scope', function ($scope) {
$scope.clickMe= function (id) {
console.log("button: " + id);
}
}]);
I want to assign the $scope.clickMe in my directive link function and get the passed id value :
.directive('clickDir', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var click = scope.clickMe;
click = function(id) { //can I get the "id" here from controller also?
//some stuff
}
}}});
But it isn't working, could you help me?
EDIT
Some code from my HTML:
<div class="my-navbar">
<ul click-dir>
<li>
<a ng-click="clickMe('main')" href="..." class="..."></a>
</li>
</ul>
</div>
<div class="action-navbar">
<ul click-dir>
<li ng-repeat="..."> //a lot of <li> generated by ng-repeat
<a ng-click="clickMe('actions')" href="..." class="..."></a>
</li>
</ul>
</div>
<div class="search-navbar">
<ul click-dir>
<li ng-repeat="..."> //a lot of <li> generated by ng-repeat
<a ng-click="clickMe('search')" href="..." class="..."></a>
</li>
</ul>
</div>
I want to get the id parameters from ng-click in the click-dir directive because I want to make some DOM manipulation.
scope.clickMetoclick, then assign the anonymous function toclick, why?ng-clickand the custom directive? Maybe what you really want is to handle the click event in your directive...?id, I don't know that you understand me correctly