0

I have an angular controller that is instantiated several times on the same page. I want to select an element based on the class inside that controller.

HTML:

<div ng-controller="File" ng-switch-when="file" class="fine-uploader"><p class="button">1</p></div>
<div ng-controller="File" ng-switch-when="file" class="fine-uploader"><p class="button">2</p></div>

Javascript

function File($scope){
   var button = angular.element(.button);
   console.log(button);
}

I would like the console to log first the first button and then the second button.

Himmators
  • 14,278
  • 36
  • 132
  • 223

1 Answers1

1

Interact with the DOM only through directives

app.directive('myDirective',function(){
return{
    restrict: 'E', // restrict to element
    link: function(scope,element){

        //element will point to your DOM-element

    }
}
});

See: http://docs.angularjs.org/guide/directive

Further reading:

How do i think in Angular if i have a jQuery background

Community
  • 1
  • 1
Wottensprels
  • 3,307
  • 2
  • 29
  • 38
  • I looked a littlebit on dierectivies, but I have a hard time getting started. Should I put them inside my functions or... where? – Himmators Oct 17 '13 at 08:51
  • 1
    Sounds like you have a rough time understanding the basic concept in Angular. I strongly recommend the Angular Tutorial: http://docs.angularjs.org/tutorial as well as www.egghead.io for learning purposes. Try to think of directives as little modules that you could insert to your page from anywhere. A simple use case would be: create a main module for your application, then add a directive to that.Feel free to ask for further information :) – Wottensprels Oct 17 '13 at 08:53