Angular: Passing Object to Directive
http://angularjs.org/
by enigment
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<pass-object title="PASS EXISTING OBJECT"-object obj="controllerObj"></pass-object>
<pass-object title="PASS OBJECT LITERAL"-object obj="{prop: 'world'}"></pass-object>
{{controllerObj}}
</div>
JavaScript
angular.module('myApp',[])
.directive('passObject', function()
{
return {
restrict: 'E',
scope: { title: '@', obj: '=' },
template: '<div>{{title}}: Hello, {{obj.prop}}!</div>'
};
})
.controller('MyCtrl', function ($scope)
{
$scope.controllerObj = {prop: 'world'};
});