@@ -404,40 +404,43 @@ we call an **isolate scope**. To do this, we can use a directive's `scope` optio
404
404
return {
405
405
restrict: 'E',
406
406
scope: {
407
- customer : '=customer '
407
+ customerInfo : '=info '
408
408
},
409
- templateUrl: 'my-customer.html'
409
+ templateUrl: 'my-customer-iso .html'
410
410
};
411
411
});
412
412
</file>
413
413
<file name="index.html">
414
414
<div ng-controller="Ctrl">
415
- <my-customer customer ="naomi"></my-customer>
415
+ <my-customer info ="naomi"></my-customer>
416
416
<hr>
417
- <my-customer customer ="igor"></my-customer>
417
+ <my-customer info ="igor"></my-customer>
418
418
</div>
419
419
</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}}
422
422
</file>
423
423
</example>
424
424
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`.
427
427
428
428
Let's take a closer look at the scope option:
429
429
430
430
```javascript
431
431
//...
432
432
scope: {
433
- customer : '=customer '
433
+ customerInfo : '=info '
434
434
},
435
435
//...
436
436
```
437
437
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.
441
444
442
445
<div class="alert alert-warning">
443
446
**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
449
452
directive's scope, you can use this shorthand syntax:
450
453
451
454
```javascript
452
- // ...
455
+ ...
453
456
scope: {
454
- // same as '=customer'
457
+ // same as '=customer'
455
458
customer: '='
456
459
},
457
- // ...
460
+ ...
458
461
```
459
462
460
463
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:
475
478
return {
476
479
restrict: 'E',
477
480
scope: {
478
- customer : '=customer '
481
+ customerInfo : '=info '
479
482
},
480
483
templateUrl: 'my-customer-plus-vojta.html'
481
484
};
482
485
});
483
486
</file>
484
487
<file name="index.html">
485
488
<div ng-controller="Ctrl">
486
- <my-customer customer ="naomi"></my-customer>
489
+ <my-customer info ="naomi"></my-customer>
487
490
</div>
488
491
</file>
489
492
<file name="my-customer-plus-vojta.html">
490
- Name: {{customer .name}} Address: {{customer .address}}
493
+ Name: {{customerInfo .name}} Address: {{customerInfo .address}}
491
494
<hr>
492
495
Name: {{vojta.name}} Address: {{vojta.address}}
493
496
</file>
0 commit comments