最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - ng-focus and ng-blur not working while ng-click works fine in input element - Stack Overflow

matteradmin6PV0评论
<input ng-model="t" ng-change="updateV()" ng-blur="blur()" ng-focus="blur()" ng-click="blur()"/>

I make a fiddle to this question:/

anyone can help? thx!

<input ng-model="t" ng-change="updateV()" ng-blur="blur()" ng-focus="blur()" ng-click="blur()"/>

I make a fiddle to this question:http://jsfiddle/tjfdfs/6Mqd6/

anyone can help? thx!

Share Improve this question asked Sep 16, 2013 at 8:04 tjfdfstjfdfs 73910 silver badges26 bronze badges 5
  • Which version are you using? Try using version 1.2.0 – AlwaysALearner Commented Sep 16, 2013 at 8:08
  • I read source of todoMVC of angular. he write todoBlur and todoFocus directives manually. So can I conclude this: I still need to write these two directives by myself? – tjfdfs Commented Sep 16, 2013 at 8:11
  • Not if you 're using version 1.2.0. in which these are already included. – AlwaysALearner Commented Sep 16, 2013 at 8:14
  • @CodeHater, thanks, I use 1.1.1 because it's latest version provided by jsfiddle . I will try 1.2.0 and see if it can work. – tjfdfs Commented Sep 16, 2013 at 8:15
  • You can load the version of your choice using the <script tag in the fiddle. – AlwaysALearner Commented Sep 16, 2013 at 8:50
Add a ment  | 

2 Answers 2

Reset to default 3

Both ng-focus and ng-blur directives are not supported in the current stable branch (1.0.x). The corresponding code has been added to master just 2 months ago.

Expect to have them in 1.2.0 branch. Actually, if you're able to work with the products marked as unstable in your application, try 1.2.0rc1 to have them supported already.

I'm working with angular 1.07 and as much as I know it does not support ng-blur nor ng-focus at all. You will have to write them by your self as follows.

var myApp = angular.module('myApp', ['App_ui']);
angular.module("App_ui", []).directive('uiBlur', function () {
  return function (scope, elem, attrs) {
      elem.bind('blur', function () {
          scope.$apply(attrs.uiBlur);
      });
   };
 });
Post a comment

comment list (0)

  1. No comments so far