Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs: Get element in controller

I am new to angularjs, I know that $scope represent a connection between the controller and the view, But is there a way besides looking for class="ng-scope" to get the scope element, I mean something like that:

function someControllerFunc($scope){        $scope.element; } 

I know that same controller can be assigned to multiple scopes, So maybe it is not possible.

like image 336
Aviel Fedida Avatar asked Jan 23 '14 14:01

Aviel Fedida


People also ask

How do you access $scope in console?

To examine the scope in the debugger: Right click on the element of interest in your browser and select 'inspect element'. You should see the browser debugger with the element you clicked on highlighted. The debugger allows you to access the currently selected element in the console as $0 variable.

What is $element in AngularJS?

element is an alias for the jQuery function. If jQuery is not available, angular. element delegates to AngularJS's built-in subset of jQuery, called "jQuery lite" or jqLite. jqLite is a tiny, API-compatible subset of jQuery that allows AngularJS to manipulate the DOM in a cross-browser compatible way.

What is Controlleras in AngularJS?

In AngularJS, a Controller is defined by a JavaScript constructor function that is used to augment the AngularJS Scope. Controllers can be attached to the DOM in different ways.

Can we use document getElementById in AngularJS?

You can use document. getElementById() in Angularjs, but manipulating HTML in a controller is not a good practice. I recommend you to create a directive and do this kind of stuff there.


1 Answers

You can pass in the element to the controller, just like the scope:

function someControllerFunc($scope, $element){  } 
like image 50
apohl Avatar answered Sep 19 '22 15:09

apohl