@@ -303,6 +303,7 @@ The `restrict` option is typically set to:
303
303
* `'A'` - only matches attribute name
304
304
* `'E'` - only matches element name
305
305
* `'C'` - only matches class name
306
+ * `'M'` - only matches comment
306
307
307
308
These restrictions can all be combined as needed:
308
309
@@ -646,6 +647,7 @@ To do this, we need to use the `transclude` option.
646
647
return {
647
648
restrict: 'E',
648
649
transclude: true,
650
+ scope: {},
649
651
templateUrl: 'my-dialog.html'
650
652
};
651
653
});
@@ -656,8 +658,7 @@ To do this, we need to use the `transclude` option.
656
658
</div>
657
659
</file>
658
660
<file name="my-dialog.html">
659
- <div class="alert" ng-transclude>
660
- </div>
661
+ <div class="alert" ng-transclude></div>
661
662
</file>
662
663
</example>
663
664
@@ -679,7 +680,7 @@ that redefines `name` as `Jeff`. What do you think the `{{name}}` binding will r
679
680
transclude: true,
680
681
scope: {},
681
682
templateUrl: 'my-dialog.html',
682
- link: function (scope, element ) {
683
+ link: function (scope) {
683
684
scope.name = 'Jeff';
684
685
}
685
686
};
@@ -691,8 +692,7 @@ that redefines `name` as `Jeff`. What do you think the `{{name}}` binding will r
691
692
</div>
692
693
</file>
693
694
<file name="my-dialog.html">
694
- <div class="alert" ng-transclude>
695
- </div>
695
+ <div class="alert" ng-transclude></div>
696
696
</file>
697
697
</example>
698
698
@@ -703,7 +703,7 @@ The `transclude` option changes the way scopes are nested. It makes it so that t
703
703
transcluded directive have whatever scope is outside the directive, rather than whatever scope is on
704
704
the inside. In doing so, it gives the contents access to the outside scope.
705
705
706
- Note that if the directive did not create its own scope, then `scope` in `scope.name = 'Jeff'; ` would
706
+ Note that if the directive did not create its own scope, then `scope` in `scope.name = 'Jeff'` would
707
707
reference the outside scope and we would see `Jeff` in the output.
708
708
709
709
This behavior makes sense for a directive that wraps some content, because otherwise you'd have to
@@ -776,9 +776,9 @@ function.
776
776
777
777
Often it's desirable to pass data from the isolate scope via an expression to the
778
778
parent scope, this can be done by passing a map of local variable names and values into the expression
779
- wrapper fn . For example, the hideDialog function takes a message to display when the dialog is hidden.
780
- This is specified in the directive by calling `close({message: 'closing for now'})`. Then the local
781
- variable `message` will be available within the `on-close` expression.
779
+ wrapper function . For example, the ` hideDialog` function takes a message to display when the dialog
780
+ is hidden. This is specified in the directive by calling `close({message: 'closing for now'})`.
781
+ Then the local variable `message` will be available within the `on-close` expression.
782
782
783
783
<div class="alert alert-success">
784
784
**Best Practice:** use `&attr` in the `scope` option when you want your directive
@@ -837,7 +837,7 @@ element?
837
837
}]);
838
838
</file>
839
839
<file name="index.html">
840
- <span my-draggable>Drag ME </span>
840
+ <span my-draggable>Drag Me </span>
841
841
</file>
842
842
</example>
843
843
@@ -882,7 +882,7 @@ to which tab is active.
882
882
})
883
883
.directive('myPane', function() {
884
884
return {
885
- require: '^myTabs',
885
+ require: '^^ myTabs',
886
886
restrict: 'E',
887
887
transclude: true,
888
888
scope: {
@@ -898,11 +898,9 @@ to which tab is active.
898
898
<file name="index.html">
899
899
<my-tabs>
900
900
<my-pane title="Hello">
901
- <h4>Hello</h4>
902
901
<p>Lorem ipsum dolor sit amet</p>
903
902
</my-pane>
904
903
<my-pane title="World">
905
- <h4>World</h4>
906
904
<em>Mauris elementum elementum enim at suscipit.</em>
907
905
<p><a href ng-click="i = i + 1">counter: {{i || 0}}</a></p>
908
906
</my-pane>
@@ -919,22 +917,25 @@ to which tab is active.
919
917
</div>
920
918
</file>
921
919
<file name="my-pane.html">
922
- <div class="tab-pane" ng-show="selected" ng-transclude>
920
+ <div class="tab-pane" ng-show="selected">
921
+ <h4>{{title}}</h4>
922
+ <div ng-transclude></div>
923
923
</div>
924
924
</file>
925
925
</example>
926
926
927
- The `myPane` directive has a `require` option with value `^myTabs`. When a directive uses this
928
- option, `$compile` will throw an error unless the specified controller is found. The `^` prefix
929
- means that this directive searches for the controller on its parents (without the `^` prefix, the
930
- directive would look for the controller on just its own element).
927
+ The `myPane` directive has a `require` option with value `^^myTabs`. When a directive uses this
928
+ option, `$compile` will throw an error unless the specified controller is found. The `^^` prefix
929
+ means that this directive searches for the controller on its parents. (A `^` prefix would make the
930
+ directive look for the controller on its own element or its parents; without any prefix, the
931
+ directive would look on its own element only.)
931
932
932
933
So where does this `myTabs` controller come from? Directives can specify controllers using
933
934
the unsurprisingly named `controller` option. As you can see, the `myTabs` directive uses this
934
935
option. Just like `ngController`, this option attaches a controller to the template of the directive.
935
936
936
- If it is necessary to reference the controller or any functions bound to the controller's scope in
937
- the template, you can use the option `controllerAs` to specify the name of the controller as an alias.
937
+ If it is necessary to reference the controller or any functions bound to the controller from the
938
+ template, you can use the option `controllerAs` to specify the name of the controller as an alias.
938
939
The directive needs to define a scope for this configuration to be used. This is particularly useful
939
940
in the case when the directive is used as a component.
940
941
@@ -949,7 +950,7 @@ The corresponding parameter being sent to the `link` function will also be an ar
949
950
angular.module('docsTabsExample', [])
950
951
.directive('myPane', function() {
951
952
return {
952
- require: ['^myTabs', '^ ngModel'],
953
+ require: ['^^ myTabs', 'ngModel'],
953
954
restrict: 'E',
954
955
transclude: true,
955
956
scope: {
@@ -985,4 +986,3 @@ available in the {@link guide/compiler compiler guide}.
985
986
986
987
The {@link ng.$compile `$compile` API} page has a comprehensive list of directive options for
987
988
reference.
988
-
0 commit comments