最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论
<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);
      });
   };
 });
发布评论

评论列表(0)

  1. 暂无评论