angular.js - angular的指令中的controller可以和link进行数据交互吗,自定义指令的controller怎么操作focus?
PHP中文网
PHP中文网 2017-05-15 17:05:08
0
2
648

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

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
Ty80

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

为情所困

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. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template