Angular on directive scopes

a short demo on scope with directives

by de Montalembert Jonathan

HTML

<script type='text/ng-template' id='templates/blob.html'>
    <div ng-repeat="user in users">
        {{user.name}}
    </div>
</script>
<div ng-controller="MainCtrl">
<blob users="main.users"></blob>
</div>

JavaScript

var app = angular.module('app', []);
app.controller('MainCtrl', function ($scope) {
    // Best practice: always assign an object to the scope rather than a primitive
    // to avoid scope issues
    // http://blog.carbonfive.com/2014/02/11/angularjs-scopes-an-introduction
    $scope.main = { users: [{
        name: 'jo',
        age: 28
    }, {
        name: 'so',
        age: 23
    }]};
});
app.directive('blob', function () {
    return {
        restrict: 'E',
        scope: {
            users: "="
        },
        templateUrl: 'templates/blob.html',
        link: function (scope, elem, attr) {

        }
    };
});

angular.bootstrap(document.body, ['app'])