2

I don't know how to focus on an input when clicking on a button in angularjs.

I create a simple demo which can't work here: http://plnkr.co/edit/NS0jJE9ttakNm8nc6QkZ?p=preview

This is the main code:

app.controller('MainCtrl', function($scope, $element) {
  $scope.name = 'World';
  $scope.myfocus = function(){
    $element.find("#myinput").???? // what to do here?
  }
});
Freewind
  • 193,756
  • 157
  • 432
  • 708

1 Answers1

2

You need to load jquery before loading angular.

See this updated plunker with load order changed and some changes to how you were trying to focus the element http://plnkr.co/edit/PLi1BiI83GKdAvSGufCP

and this previously asked question Error: "Selectors not implemented"

And fastreload is right about not dealing with the DOM in the controller.

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

Community
  • 1
  • 1
sparkalow
  • 177
  • 5
  • 2
    "fastreload is right about not dealing with the DOM in the controller" -- so here is a [directive implementation](http://stackoverflow.com/questions/15518772/easy-dom-manipulation-in-angularjs) – Mark Rajcok Mar 21 '13 at 16:42
  • Mix jquery with angularjs is a bad practise. Try to use the element attribute in the link function of the directive to do this.This is not a right answer. – Pablo Ezequiel Leone Apr 28 '14 at 09:01