ng:directive - watch attributes interpolation

execute attr.$observe

by Krzysztof Safjanowski

HTML

<div ng-app='app'>
    <div ng-controller='app'>
        <input type="text" ng-model='baz' />
        <foo-bar baz="{{ baz }}"></foo-bar>
    </div>
</div>

JavaScript

angular.module('app', []).controller('app', function($scope) {
    $scope.baz = '';
}).directive('fooBar', function() {
    return {
        template: '<div>Hello {{ foo }}</div>',
        replace: true,
        restrict: 'E',
        scope: {
            foo: '@baz'
        },
        link: function(scope, element, attr) {
            attr.$observe('baz', function(v) {
                console.log('value:', v);   
            })
        }
    }
})