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

This is my Angular code:angular.module('player', []).directive('playButton', funct

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!');
 });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744909604a4600466.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信