|
279 | 279 | * passed to the linking function will also be an object with matching keys, whose values will hold the corresponding
|
280 | 280 | * controllers.
|
281 | 281 | *
|
| 282 | + * If the `require` property is an object and the directive provides a controller, then the required controllers are |
| 283 | + * bound to the controller using the keys of the `require` property. See the {@link $compileProvider#component} helper |
| 284 | + * for an example of how this can be used. |
| 285 | + * |
282 | 286 | * If no such directive(s) can be found, or if the directive does not have a controller, then an error is raised
|
283 | 287 | * (unless no link function is specified, in which case error checking is skipped). The name can be prefixed with:
|
284 | 288 | *
|
@@ -1025,6 +1029,80 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
1025 | 1029 | *
|
1026 | 1030 | * ```
|
1027 | 1031 | *
|
| 1032 | + * ### Intercomponent Communication |
| 1033 | + * Directives can require the controllers of other directives to enable communication |
| 1034 | + * between the directives. This can be achieved in a component by providing an |
| 1035 | + * object mapping for the `require` property. Here is the tab pane example built |
| 1036 | + * from components... |
| 1037 | + * |
| 1038 | + * <example module="docsTabsExample"> |
| 1039 | + * <file name="script.js"> |
| 1040 | + * angular.module('docsTabsExample', []) |
| 1041 | + * .component('myTabs', { |
| 1042 | + * transclude: true, |
| 1043 | + * controller: function() { |
| 1044 | + * var panes = this.panes = []; |
| 1045 | + * |
| 1046 | + * this.select = function(pane) { |
| 1047 | + * angular.forEach(panes, function(pane) { |
| 1048 | + * pane.selected = false; |
| 1049 | + * }); |
| 1050 | + * pane.selected = true; |
| 1051 | + * }; |
| 1052 | + * |
| 1053 | + * this.addPane = function(pane) { |
| 1054 | + * if (panes.length === 0) { |
| 1055 | + * this.select(pane); |
| 1056 | + * } |
| 1057 | + * panes.push(pane); |
| 1058 | + * }; |
| 1059 | + * }, |
| 1060 | + * templateUrl: 'my-tabs.html' |
| 1061 | + * }) |
| 1062 | + * .component('myPane', { |
| 1063 | + * transclude: true, |
| 1064 | + * require: {tabsCtrl: '^myTabs'}, |
| 1065 | + * bindings: { |
| 1066 | + * title: '@' |
| 1067 | + * }, |
| 1068 | + * controller: function() { |
| 1069 | + * this.$onInit = function() { |
| 1070 | + * this.tabsCtrl.addPane(this); |
| 1071 | + * console.log(this); |
| 1072 | + * }; |
| 1073 | + * }, |
| 1074 | + * templateUrl: 'my-pane.html' |
| 1075 | + * }); |
| 1076 | + * </file> |
| 1077 | + * <file name="index.html"> |
| 1078 | + * <my-tabs> |
| 1079 | + * <my-pane title="Hello"> |
| 1080 | + * <h4>Hello</h4> |
| 1081 | + * <p>Lorem ipsum dolor sit amet</p> |
| 1082 | + * </my-pane> |
| 1083 | + * <my-pane title="World"> |
| 1084 | + * <h4>World</h4> |
| 1085 | + * <em>Mauris elementum elementum enim at suscipit.</em> |
| 1086 | + * <p><a href ng-click="i = i + 1">counter: {{i || 0}}</a></p> |
| 1087 | + * </my-pane> |
| 1088 | + * </my-tabs> |
| 1089 | + * </file> |
| 1090 | + * <file name="my-tabs.html"> |
| 1091 | + * <div class="tabbable"> |
| 1092 | + * <ul class="nav nav-tabs"> |
| 1093 | + * <li ng-repeat="pane in $ctrl.panes" ng-class="{active:pane.selected}"> |
| 1094 | + * <a href="" ng-click="$ctrl.select(pane)">{{pane.title}}</a> |
| 1095 | + * </li> |
| 1096 | + * </ul> |
| 1097 | + * <div class="tab-content" ng-transclude></div> |
| 1098 | + * </div> |
| 1099 | + * </file> |
| 1100 | + * <file name="my-pane.html"> |
| 1101 | + * <div class="tab-pane" ng-show="$ctrl.selected" ng-transclude></div> |
| 1102 | + * </file> |
| 1103 | + * </example> |
| 1104 | + * |
| 1105 | + * |
1028 | 1106 | * <br />
|
1029 | 1107 | * Components are also useful as route templates (e.g. when using
|
1030 | 1108 | * {@link ngRoute ngRoute}):
|
|
0 commit comments