Example usage:
In a template:
<element focus-on="modelUpdated">
</element>
In a controller:
$scope.$broadcast('modelUpdated');
app.directive('focusOn', function() { | |
return { | |
restrict: 'A', | |
scope: { | |
'continuePropagation': '@' | |
}, | |
link: function(scope, element, attrs) { | |
scope.$on(attrs.focusOn, function(event) { | |
element[0].focus(); | |
if (!scope.continuePropagation && event.stopPropagation) { | |
event.stopPropagation(); | |
} | |
}); | |
}, | |
}; | |
}) | |
}); |