search

Home  >  Q&A  >  body text

angular.js - Can the controller in the angular directive interact with the link for data? How does the controller in the custom directive operate focus?

Or can the controller of the command obtain element and attribute objects? I want to call the main command controller method in the sub-command and operate focus in the method, but operating element[0].focus() in the controller does not cause the cursor to Positioning, the instruction encapsulates ng-repeat, because the link is executed after the instruction is compiled, so there will be no response if written directly in the link

PHP中文网PHP中文网2868 days ago716

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 17:07:08

    http://stackoverflow.com/a/24...

    reply
    0
  • 为情所困

    为情所困2017-05-15 17:07:08

    The

    link method has a fourth parameter, which represents the controller of the current directive or parent directive.

    Write this in the command controller:

    controller: function() {
      this.xxx = function() {}
    }

    link in:

    link: function(scope, elem, attr, parent) {
      parent.xxx()
    }

    You can call methods in the controller directly in the link. On the other hand, if you call the method in link in the controller, you don't know how to operate it. . .

    reply
    0
  • Cancelreply