Steely Wing
Steely Wing

Reputation: 17607

Is there any difference between `element` and `iElement` in AngularJS?

I am using AngularJS and jQuery, AngularJS official tutorial using iElement to inject, but some other tutorial using element, is there any different? the following btn1 and btn2 also work, element and iElement also will wrap by jQuery.

var app = angular.module('myApp', []);

app.directive('btn1', function () {
    return function (scope, element) {
        element.click(function () {
            $(this).css('background', '#666');
        });
    };
});

app.directive('btn2', function () {
    return function (scope, iElement) {
        iElement.click(function () {
            $(this).css('background', '#666');
        });
    };
});

Upvotes: 1

Views: 1862

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

No, there are no difference, both are just two variable names. You can use any name instead of element/iElement like el/eleme etc, the only factor that matters in this is the values passed to the callback in this case it is the link callback function which passes the scope, element, attributes and controllers.

When it matters is when you use it an environment where argument injection is used like in the controller function or in the directive function where the parameter names are used for injecting the parameters

Upvotes: 2

Related Questions