How do I get current scope dom-element in AngularJS controller? How do I get current scope dom-element in AngularJS controller? angularjs angularjs

How do I get current scope dom-element in AngularJS controller?


In controller:

function innerItem($scope, $element){    var jQueryInnerItem = $($element); }


The better and correct solution is to have a directive. The scope is the same, whether in the controller of the directive or the main controller. Use $element to do DOM operations. The method defined in the directive controller is accessible in the main controller.

Example, finding a child element:

var app = angular.module('myapp', []);app.directive("testDir", function () {    function link(scope, element) {     }    return {        restrict: "AE",         link: link,         controller:function($scope,$element){            $scope.name2 = 'this is second name';            var barGridSection = $element.find('#barGridSection'); //helps to find the child element.    }    };})app.controller('mainController', function ($scope) {$scope.name='this is first name'});