Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Directive for get element ID

I need to get the Element ID from AngularJs.
I have tried this but it didn't work.

angular.module('AngStarter').directive('oblInLineEditor', function() {
    return function(scope, element, attr) {
         console.log("value = " + scope.$eval(attr.id));
    }
});
like image 207
Mad Avatar asked Jul 06 '15 07:07

Mad


2 Answers

you don't need scope.eval here.

angular.module('AngStarter').directive('oblInLineEditor', function() {
    return function(scope, element, attr) {
         console.log("value = " + attr.id);
    }
});
like image 129
SSH Avatar answered Oct 12 '22 00:10

SSH


see this example: http://jsfiddle.net/kevalbhatt18/bu6jxzan/

var myApp = angular.module('AngStarter', []);

myApp.directive("oblInLineEditor", function(){
    return {
        restrict: "E",
        link: function(scope, elem, attrs) {
            console.log(elem[0].id);
            console.log(attrs.id)

        }
    }
});

like image 27
Keval Bhatt Avatar answered Oct 12 '22 00:10

Keval Bhatt