[英]How to set focus to div of TextAngular
I'm using a TextAngular. 我正在使用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. 我希望通过一些条件设置焦点,但我不明白,如何做到这一点。
Don'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: 使用text-angular
属性为元素添加名称,并添加新的属性focus
(或您想要的其他名称)并将其传递给表达式:
<div text-angular name="myEditor" focus="shouldFocus" ...
Add a directive called textAngular
like this: 添加一个名为textAngular
的指令,如下所示:
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 演示: http : //plnkr.co/edit/ML3rLNutIz1XMo3oO2UC?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.