Danil Gholtsman Danil Gholtsman - 5 months ago 32
AngularJS Question

AngularJS select DOM element which belogs directive by tag

Is there a way to select DOM element which belongs directive from I call select command?

As example - I got two directive. Eeach of them got

inside directive




<div>other input<div>

I got controllers declared in directives, which I use to handle stuff.

first (called from view1 directive)

$scope.selectView1Input = function(){
var input = angular.element('input');

second (called from view2 directive)

$scope.selectView2Input = function(){
var input = angular.element('input');

But in bouth situations it selecting the same input filed (I expected his behaviour, because it looks like just dom selector, so)

I don't want to use
s. Just simple tags, so, is there any way to do this?


You can use jQuery or the build-in jqLite to select to element:

app.directive('myDirective', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attr) {
            var input = element.find('input');