我有以下指令来自动对焦一个字段:
@H_502_1@.directive('ngAutofocus',function ($timeout) {
return {
restrict: 'A',link: function (scope,elm) {
$timeout(function () {
elm[0].focus();
});
}
};
}
我将如何测试这个?我尝试了几个像下面的选择器,但都返回错误或者false:
@H_502_1@console.log($(elm[0]).is(':focus'));我的单元测试设置如下:
@H_502_1@elm = angular.element('<input type="text" name="textfield1" ng-autofocus>'); $scope.$digest(); $compile(elm)($scope);