angular 获取焦点指令
angular.module('app').directive('focus', function ($timeout,$parse) {
return {
restrict: 'A',
link: function ($scope, $ele, $attrs, $controller) {
let model = $parse($attrs.focus);
let unBind= $scope.$watch(model, function (newValue,oldValue) {
if (newValue === true) {
$timeout(function () {
$ele[0].focus();
});
}
});
$ele.bind('blur', function () {
$scope.$apply(model.assign($scope, false));
});
$scope.$on("destroy", () => {
unBind();
})
}
}
});

浙公网安备 33010602011771号