When I use $compile to create and bind directives, how can I add a variable as an attribute? A variable is an object.
var data = { name: 'Fred' }; var dirCode = '<my-directive data-record="data"></my-directive>'; var el = $compile(dirCode)($scope); $element.append(el);
And myDirective will wait:
... scope: { record: '=' }, ...
I tried to do
`var dirCode = '<my-directive data-record="' + data + '"></my-directive>';`
also.
source share