According to the docs (specifically, the table comparing directives to components), angular components allow requiring other directives (or is it only components?). However, components do not have a link function, which could give access to the required controller. The source, contrary to documentation, seems to suggest that it is not possible to use 'require' when creating components. Which is true?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
The cited source is outdated. As of 1.5.0, component controllers can be required in other components (the same applies to directives).
An example from the guide shows the way how the components and directives should interact in 1.5 without the aid from
link
.When
require
object andbindToController
are used together, required controller instances are assigned to current controller as properties.Because this happens during directive linking, the required controllers aren't available in controller constructor, that's why
$onInit
magic method is there. If it exists, it is executed right after adding required controllers tothis
.Both
and
declaration styles are on a par under the hood and can be used interchangeably in 1.5, and
component
is a concise one.