Angular: Passing Object to Directive

http://angularjs.org/

by petran

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<div ng-controller="MyCtrl">
    <pass-object obj="obj"></pass-object>
</div>

JavaScript

var myApp = angular.module('myApp',[]);

myApp.directive('passObject', function() {
    return {
        restrict: 'E',
        scope: { obj: '=' },
        template: '<div>Hello, {{obj.prop}}!</div>',
        link: (scope, element, attrs) => {
           console.log(obj);
        }
    };
});

myApp.controller('MyCtrl', function ($scope) {
    $scope.obj = { prop: "world" };
});