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?
PHP中文网
PHP中文网 2017-05-15 17:05:08
0
2
691

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中文网

认证高级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