Reputation: 548
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));
}
});
Upvotes: 7
Views: 14555
Reputation: 6322
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)
}
}
});
Upvotes: 5
Reputation: 2553
you don't need scope.eval here.
angular.module('AngStarter').directive('oblInLineEditor', function() {
return function(scope, element, attr) {
console.log("value = " + attr.id);
}
});
Upvotes: 14