1

I have used angular-reductor editor(npm package for editor in html) I want to focus on text-area(redector editor) on ng-click below code is not working but if i remove redactor="redactor_options" from text-area it works but editor don't get display. According to angular-redector document they using jQuery method to focus but as i am working on angularjs is there any angularjs method to do this ?

In short:is there any angularjs way to focus on redector editor on ng-click ?

html file

`<div ng-click="focusInput=true">
<textarea ng-model="data.content" redactor="redactor_options" cols="30" rows="10" focus-me="focusInput"></textarea>
<div>'

Controller I have added directive for focus on textarea on ng-click

`app.directive('focusMe', function($timeout) {
  return {
    link: function(scope, element, attrs, redactor) {
      scope.$watch(attrs.focusMe, function(value) {
        if(value === true) { 
          $timeout(function() {
            element[0].focus();
            scope[attrs.focusMe] = false;
          });
        }
      });
    }
  };
});`
Kiran
  • 13
  • 4
  • if without `redactor="redactor_options"` works, this means that redactor is adding some html to text-area and this is probably the reason the `element[0].focus` doesn't work...I suggest you print your `element` on your directive to see what element is being passed to the function. – Elmer Dantas Aug 10 '17 at 14:48
  • I checked it i am getting `textarea.ng-pristine.ng-untouched.ng-valid.ng-empty context : textarea.ng-pristine.ng-untouched.ng-valid.ng-empty __proto__ : Object(0)` – Kiran Aug 10 '17 at 15:12
  • just a `string` with this information or it is an `html object`? you need to make sure you get the `html object` then you can set `focus`...print within and without `redactor="redactor_options"` to see the difference of the `element` you are getting – Elmer Dantas Aug 10 '17 at 15:16
  • Its an object am getting didnt found much difference in between them (with and without redactor="redactor_options") but without redactor in object i get dont get this `ng-untouched` but it present in with redactor – Kiran Aug 10 '17 at 15:43
  • please. create a fiddlejs with your structure and I`ll try to hel[ you – Elmer Dantas Aug 10 '17 at 15:58
  • https://jsfiddle.net/Lwk3c65f/ is it accessiable ? sorry if there is any issue i am new here i never created fiddlejs before – Kiran Aug 10 '17 at 17:45
  • as I imagined...redactor replaces your textarea...that's why it doesn't work...[see this answer](https://stackoverflow.com/questions/15470721/angularjs-redactor-plugin) . I think it will help you with this. – Elmer Dantas Aug 11 '17 at 06:55

0 Answers0