2016-04-13 53 views
2

我是angularJS的新手,尝试获取代码 - http://jsfiddle.net/atXAC/11/升级到1.4.9。将angularjs代码从1.0.3升级到1.4.9

myApp.directive('ngCustomblur', ['$parse', function($parse) { 
    return function(scope, element, attr) { 
     var fn = $parse(attr['ngCustomblur']);  
     element.bind('blur', function(event) {   
     scope.$apply(function() { 
      fn(scope, {$event:event}); 
     }); 
    }); 
} 
}]); 

请让我知道需要做些什么改变。 目前代码在1.0.3。

在此先感谢。

+1

究竟是什么问题吗? – dreamweiver

+0

我正在使用角1.4.9,无法让代码工作。小提琴中的代码是用1.0.3编写的 – user56690

+1

您在控制台中遇到什么错误? –

回答

1

其实问题是angularjs库的更高版本使它成为创建控制器的标准,这与您在jsfiddle中使用的当前语法稍有不同。

JS代码:

//defining a controller 
myApp.controller('MyCtrl',['$scope',MyCtrl]); 

function MyCtrl($scope) { 
    $scope.onBlur = function(){   
     $scope.hasFocus = false; 
    } 
} 

Working demo on JSFiddle