Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 23ba287

Browse files
maxhqpetebacondarwin
authored andcommitted
docs(guide/directive): clarify code example for isolated scopes bindings
Use different names for the attribute on the element (`info`) and the property (`customerInfo`) on the isolate scope. Before `customer` was used for both which made it harder to understand. Closes #4825
1 parent 8f1e360 commit 23ba287

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

docs/content/guide/directive.ngdoc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -404,40 +404,43 @@ we call an **isolate scope**. To do this, we can use a directive's `scope` optio
404404
return {
405405
restrict: 'E',
406406
scope: {
407-
customer: '=customer'
407+
customerInfo: '=info'
408408
},
409-
templateUrl: 'my-customer.html'
409+
templateUrl: 'my-customer-iso.html'
410410
};
411411
});
412412
</file>
413413
<file name="index.html">
414414
<div ng-controller="Ctrl">
415-
<my-customer customer="naomi"></my-customer>
415+
<my-customer info="naomi"></my-customer>
416416
<hr>
417-
<my-customer customer="igor"></my-customer>
417+
<my-customer info="igor"></my-customer>
418418
</div>
419419
</file>
420-
<file name="my-customer.html">
421-
Name: {{customer.name}} Address: {{customer.address}}
420+
<file name="my-customer-iso.html">
421+
Name: {{customerInfo.name}} Address: {{customerInfo.address}}
422422
</file>
423423
</example>
424424

425-
Looking at `index.html`, the first `<my-customer>` element binds the inner scope's `customer` to
426-
`naomi`, which we have exposed on our controller's scope. The second binds `customer` to `igor`.
425+
Looking at `index.html`, the first `<my-customer>` element binds the `info` attribute to `naomi`,
426+
which we have exposed on our controller's scope. The second binds `info` to `igor`.
427427

428428
Let's take a closer look at the scope option:
429429

430430
```javascript
431431
//...
432432
scope: {
433-
customer: '=customer'
433+
customerInfo: '=info'
434434
},
435435
//...
436436
```
437437

438-
The property name (`customer`) corresponds to the variable name of the `myCustomer` directive's
439-
isolated scope. The value of the property (`=customer`) tells `$compile` to bind to the `customer`
440-
attribute.
438+
The **scope option** is an object that contains a property for each isolate scope binding. In this
439+
case it has just one property:
440+
441+
- Its name (`customerInfo`) corresponds to the
442+
directive's **isolate scope** property `customerInfo`.
443+
- Its value (`=info`) tells `$compile` to bind to the `info` attribute.
441444

442445
<div class="alert alert-warning">
443446
**Note:** These `=attr` attributes in the `scope` option of directives are normalized just like
@@ -449,12 +452,12 @@ For cases where the attribute name is the same as the value you want to bind to
449452
directive's scope, you can use this shorthand syntax:
450453

451454
```javascript
452-
//...
455+
...
453456
scope: {
454-
// same as '=customer'
457+
// same as '=customer'
455458
customer: '='
456459
},
457-
//...
460+
...
458461
```
459462

460463
Besides making it possible to bind different data to the scope inside a directive, using an isolated
@@ -475,19 +478,19 @@ within our directive's template:
475478
return {
476479
restrict: 'E',
477480
scope: {
478-
customer: '=customer'
481+
customerInfo: '=info'
479482
},
480483
templateUrl: 'my-customer-plus-vojta.html'
481484
};
482485
});
483486
</file>
484487
<file name="index.html">
485488
<div ng-controller="Ctrl">
486-
<my-customer customer="naomi"></my-customer>
489+
<my-customer info="naomi"></my-customer>
487490
</div>
488491
</file>
489492
<file name="my-customer-plus-vojta.html">
490-
Name: {{customer.name}} Address: {{customer.address}}
493+
Name: {{customerInfo.name}} Address: {{customerInfo.address}}
491494
<hr>
492495
Name: {{vojta.name}} Address: {{vojta.address}}
493496
</file>

0 commit comments

Comments
 (0)