Skip to content

Commit 91adb13

Browse files
committed
Merge pull request johnpapa#178 from johnpapa/develop
helps clarify controller as and watches, as per question in issue johnpapa#176
2 parents 58a21fd + 19f935b commit 91adb13

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,20 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
367367

368368
Note: When creating watches in a controller using `controller as`, you can watch the `vm.*` member using the following syntax. (Create watches with caution as they add more load to the digest cycle.)
369369

370+
```html
371+
<input ng-model="vm.title"/>
372+
```
373+
370374
```javascript
371-
$scope.$watch('vm.title', function(current, original) {
372-
$log.info('vm.title was %s', original);
373-
$log.info('vm.title is now %s', current);
374-
});
375+
function SomeController($scope, $log) {
376+
var vm = this;
377+
vm.title = 'Some Title';
378+
379+
$scope.$watch('vm.title', function(current, original) {
380+
$log.info('vm.title was %s', original);
381+
$log.info('vm.title is now %s', current);
382+
});
383+
}
375384
```
376385

377386
### Bindable Members Up Top

0 commit comments

Comments
 (0)