I attempted to pass the directive attribute value to a template ID, which can then be used in another directive.
Below is my index.html code:
<my-value name="jhon"></my-value>
Here is the JavaScript code:
.directive('myValue',function(){
return {
restrict:"E",
templateUrl:"myname.html",
scope: {
name:"="
},
link:function(scope,element,attr) {
}
}
});
This is my template code (myname.html):
<div>
<p slide heading="name"></p>
</div>
In the above code snippet, "slide" refers to another directive.
Here is the code for the slide directive:
.directive('slide',function(){
return{
restrict:"A",
link:function(scope,elem,attr){
console.log(attr.heading);
// I need the name that was assigned in index.html, like "attr.heading = jhon"
}
}
})
The issue I am facing is I assigned name="jhon"
to the my-value directive. I want to dynamically send that name to the template of the my-value directive, and from there, I need to assign that name to the heading attribute of the slide directive as heading=name
. This name should then be utilized in the link function of the slide directive because I aim to pass the name dynamically from one directive to its template and subsequently assign it to another directive's attribute, using it within the slide directive's link function.
Thank you in advance!