admin管理员组

文章数量:1405636

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

本文标签: javascriptAngular directive link method giving back element as objectStack Overflow