@@ -751,9 +751,12 @@ own behavior to it.
751
751
angular.module('docsIsoFnBindExample', [])
752
752
.controller('Controller', ['$scope', '$timeout', function($scope, $timeout) {
753
753
$scope.name = 'Tobias';
754
- $scope.hideDialog = function () {
754
+ $scope.message = '';
755
+ $scope.hideDialog = function (message) {
756
+ $scope.message = message;
755
757
$scope.dialogIsHidden = true;
756
758
$timeout(function () {
759
+ $scope.message = '';
757
760
$scope.dialogIsHidden = false;
758
761
}, 2000);
759
762
};
@@ -771,14 +774,15 @@ own behavior to it.
771
774
</file>
772
775
<file name="index.html">
773
776
<div ng-controller="Controller">
774
- <my-dialog ng-hide="dialogIsHidden" on-close="hideDialog()">
777
+ {{message}}
778
+ <my-dialog ng-hide="dialogIsHidden" on-close="hideDialog(message)">
775
779
Check out the contents, {{name}}!
776
780
</my-dialog>
777
781
</div>
778
782
</file>
779
783
<file name="my-dialog-close.html">
780
784
<div class="alert">
781
- <a href class="close" ng-click="close()">×</a>
785
+ <a href class="close" ng-click="close({message: 'closing for now'} )">×</a>
782
786
<div ng-transclude></div>
783
787
</div>
784
788
</file>
@@ -795,9 +799,15 @@ callback functions to directive behaviors.
795
799
796
800
When the user clicks the `x` in the dialog, the directive's `close` function is called, thanks to
797
801
`ng-click.` This call to `close` on the isolated scope actually evaluates the expression
798
- `hideDialog()` in the context of the original scope, thus running `Controller`'s `hideDialog`
802
+ `hideDialog(message )` in the context of the original scope, thus running `Controller`'s `hideDialog`
799
803
function.
800
804
805
+ Often it's desirable to pass data from the isolate scope via an expression to the
806
+ parent scope, this can be done by passing a map of local variable names and values into the expression
807
+ wrapper fn. For example, the hideDialog function takes a message to display when the dialog is hidden.
808
+ This is specified in the directive by calling `close({message: 'closing for now'})`. Then the local
809
+ variable `message` will be available within the `on-close` expression.
810
+
801
811
<div class="alert alert-success">
802
812
**Best Practice:** use `&attr` in the `scope` option when you want your directive
803
813
to expose an API for binding to behaviors.
0 commit comments