How to click a button and focus on another input in angularjs?

12,019

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

Share:
12,019
Freewind
Author by

Freewind

A programmer ([email protected])

Updated on June 04, 2022

Comments

  • Freewind
    Freewind almost 2 years

    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?
      }
    });