javascript - How to set focus to div of TextAngular - Stack Overflow

I'm using a TextAngular.<divtext-angularta-toolbar="[['bold','italics'

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7

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:

<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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信