I want dynamically set attributes for child directive.
But I can not do it.
In the example I want to set attribute
namewith valueJohn.
UPD: In this case, I can not determine the exact set of attributes. And I need to define them dynamically. For example, this is part of a third-party library.
angular.module('app', []);
angular.module('app')
.directive('wrapper', wrapper);
angular.module('app')
.directive('inWrapper', inWrapper);
angular.bootstrap(
document.getElementById('root'), ['app']
);
function wrapper() {
return {
transclude: true,
template: '<div ng-transclude></div>',
link: function linkFn(scope, element, attrs, ctrl, transcludeFn) {
transcludeFn(
scope,
function(clone) {
clone.find('in-wrapper').attr('name', 'John');
}
);
}
}
}
function inWrapper() {
return {
scope: {
name: '@'
},
template: 'Hello, {{name}}',
link: function linkFunc(scope) {
if (!scope.name) {
scope.name = 'Empty';
}
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div id="root">
<wrapper>
<in-wrapper></in-wrapper>
</wrapper>
</div>