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));
}
});
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));
}
});
Share
Improve this question
edited Jul 6, 2015 at 7:06
Cerbrus
72.9k19 gold badges136 silver badges150 bronze badges
asked Jul 6, 2015 at 7:04
MadMad
5481 gold badge11 silver badges28 bronze badges
2 Answers
Reset to default 14you don't need scope.eval here.
angular.module('AngStarter').directive('oblInLineEditor', function() {
return function(scope, element, attr) {
console.log("value = " + attr.id);
}
});
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)
}
}
});