NGCS - hello world with Angular, pt 2
$watch for model value changes
by Krzysztof Safjanowski
HTML
<div ng-controller='app as app'>
<input type='text' ng-model='app.hello'>
<div hello-world='app.hello'></div>
</div>
CoffeeScript
angular
.module('app', [])
.controller('app', ->
@hello = 'foo'
)
.directive('helloWorld', ->
return {
restrict: 'A'
scope:
world: '=helloWorld'
link: (scope, element, attrs) ->
scope.$watch 'world', (newArg) -> element.text "Hello #{scope.world}"
}
)
angular.bootstrap document, ["app"]