Currently, I am utilizing angular and seeking to add a script to my directive's template. My goal is to create a function that can take the necessary parameters for the script and return it as a string. This approach would prevent me from having to embed lengthy JavaScript files as strings.
Below is the directive in question:
directive
function barchart() {
return {
restrict: 'EA',
replace: true,
template: `
<div id="canvas" class ="panel-body container-fluid">
<div class ="ui centered grid">
<div>
<div id="title"></div>
<div id="chart"></div>
</div>
</div>
</div>
`,
scope: {
revenues: "=revenues"
},
link: function ($scope, $element, $attrs) {
$scope.$watch('revenues', function (rev) {
if (typeof rev != 'undefined') {
$element.append(`<script> (render(${rev}))(); </script>`);
}
});
}
}
}
I am striving for something similar to this, but encountering issues.
render (function that should return a script)
function render(params){
return (function(){
$('#chart').append('<p> params </p>');
})();
}
error
rev is not defined