I'm using a TextAngular.
<div
text-angular
ta-toolbar="[['bold','italics', 'underline', 'ol', 'ul']]"
ng-model="model"></div>
I want to set focus by some condition, but I don't understand, how to do this.
I'm using a TextAngular.
<div
text-angular
ta-toolbar="[['bold','italics', 'underline', 'ol', 'ul']]"
ng-model="model"></div>
I want to set focus by some condition, but I don't understand, how to do this.
Share Improve this question asked Jan 22, 2015 at 11:31 Mike_DeviceMike_Device 6722 gold badges9 silver badges26 bronze badges1 Answer
Reset to default 7Don't know your exact needs, but this should be a start.
Add a name to the element with the text-angular
attribute and add a new attribute focus
(or some other name you want) and pass it an expression:
<div text-angular name="myEditor" focus="shouldFocus" ...
Add a directive called textAngular
like this:
app.directive('textAngular', ['$parse', '$timeout', 'textAngularManager',
function($parse, $timeout, textAngularManager) {
return {
link: function(scope, element, attributes) {
// Parse the focus expression
var shouldFocus = $parse(attributes.focus)(scope);
if (!shouldFocus) return;
$timeout(function() {
// Retrieve the scope and trigger focus
var editorScope = textAngularManager.retrieveEditor(attributes.name).scope;
editorScope.displayElements.text.trigger('focus');
}, 0, false);
}
};
}
]);
Demo: http://plnkr.co/edit/ML3rLNutIz1XMo3oO2UC?p=preview
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744902565a4600062.html
评论列表(0条)