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

javascript - Angular directive link method giving back element as object - Stack Overflow

programmeradmin3浏览0评论

This is my Angular code:

angular.module('player', [])
.directive('playButton', function() {
    return {
        restrict: 'A',
                    /* I want to get the element parameter bellow as HTMl, 
                    not an object with an element stored within.
                    I don't want to access the HTML element as element[0]*/
        link: function($scope, /* this parameter -> */ element, attr) {
            console.log(typeof(element));
            // element[0].addEvent('click', function() {
            //  console.log('Moo!');
            // });
        }
    }
})

What i want to achieve is getting the element parameter within the link method as html, so that i can manipulate it with MooTools. Is there any way to prevent the use of the [0] after the element variable?

This is my Angular code:

angular.module('player', [])
.directive('playButton', function() {
    return {
        restrict: 'A',
                    /* I want to get the element parameter bellow as HTMl, 
                    not an object with an element stored within.
                    I don't want to access the HTML element as element[0]*/
        link: function($scope, /* this parameter -> */ element, attr) {
            console.log(typeof(element));
            // element[0].addEvent('click', function() {
            //  console.log('Moo!');
            // });
        }
    }
})

What i want to achieve is getting the element parameter within the link method as html, so that i can manipulate it with MooTools. Is there any way to prevent the use of the [0] after the element variable?

Share Improve this question asked Aug 24, 2013 at 23:21 jvakuilerjvakuiler 5281 gold badge6 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

No. Angular return a jQlite object. So, like jQuery, to select current html element you need to use element[0]. An alternative would be to assign a variable to element[0].

var elm = element[0];

elm.addEvent('click', function() {
     console.log('Moo!');
 });
发布评论

评论列表(0)

  1. 暂无评论