Home  >  Q&A  >  body text

angular.js - angular的指令中的controller可以和link进行数据交互吗,自定义指令的controller怎么操作focus?

或者指令的controller可以获取element,attribute对象吗,想在子指令调取主指令controller方法,并在方法里面操作focus,但是在controller里操作element[0].focus()并没有使得光标定位,指令封装的是ng-repeat,因为link是在指令编译后执行的,所以直接在link里面写会没有响应

PHP中文网PHP中文网2713 days ago615

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