如何将焦点设置到 TextAngular 的 div
How to set focus to div of TextAngular
我正在使用 TextAngular。
<div
text-angular
ta-toolbar="[['bold','italics', 'underline', 'ol', 'ul']]"
ng-model="model"></div>
我想通过一些条件来设置焦点,但我不明白该怎么做。
不知道您的确切需求,但这应该是一个开始。
为具有 text-angular
属性的元素添加一个名称并添加一个新属性 focus
(或您想要的其他名称)并向其传递一个表达式:
<div text-angular name="myEditor" focus="shouldFocus" ...
像这样添加一个名为 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);
}
};
}
]);
我正在使用 TextAngular。
<div
text-angular
ta-toolbar="[['bold','italics', 'underline', 'ol', 'ul']]"
ng-model="model"></div>
我想通过一些条件来设置焦点,但我不明白该怎么做。
不知道您的确切需求,但这应该是一个开始。
为具有 text-angular
属性的元素添加一个名称并添加一个新属性 focus
(或您想要的其他名称)并向其传递一个表达式:
<div text-angular name="myEditor" focus="shouldFocus" ...
像这样添加一个名为 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);
}
};
}
]);