最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS Directive for get element ID - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 14

you 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)

        }
    }
});

发布评论

评论列表(0)

  1. 暂无评论