-1

I am trying to find out a way to write a Angular JS directive which will set focus on a textbox after saving data using $http.

I am trying to solve the following problem.

  1. User fill up a form
  2. On ng-submit I save the data using $http call.
  3. I want to put the focus to first element of form after successfull save.

As I understand that DOM manipulation needs to be done via Directive. Can anyone provide a simple directive sample code to do this?

  • UPDATE - I should put my code with my question. Here it is

Sorry I should put my code before. Here is what I tried but didn't work

Html Code

4

1 回答 1

1

您的问题没有显示任何研究工作,因此很可能没有答案或被关闭(除了它是重复的事实)。不过,这里有一些简单的示例代码

app.directive('focusMe', function($timeout) {
 return {
   link: function(scope, element) {

        element[0].focus(); 

    }
  });
}

在指令链接函数中,您可以访问该元素。使用它来处理它。也可以看看:

Angular API:元素

于 2013-07-12T13:29:15.173 回答