Directive Attributes

by yoorek

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js"></script>
<body ng-app="app">
    <my-directive attr1='model'></my-directive>
</body>

JavaScript

angular.module('app', [])
    .run(function ($rootScope, $timeout) {
    $rootScope.model = 'Before';

    $timeout(function () {
        $rootScope.model = 'After';
    }, 1000);
})
    .directive('myDirective', function () {
    return function (scope, element, attrs) {
        scope.$watch(attrs.attr1, function (value) {
            element.html(value);
        });
    }
});