See this plunker
I have an html that uses a custom angular directive
<body ng-controller="myCtrl"> <h1>Hello Plunker!</h1> <div><sample attributeone="Sample Attribute"></sample></div> </body>
and my directive is as follows:
myApp.directive('sample', function() { var value = ""; return { replace: true, restrict: 'E', scope : false, template: '<div>This is a sample Paragraph '+ value + '</div>', compile: function ( tElement, tAttributes ) { return { pre: function preLink( scope, element, attributes ) { console.log( attributes.log + ' (pre-link)' ); value = tAttributes.attributeone; } }; } }; });
In my opinion, pre of compile must be executed before the template is returned, and value must be set to "Sample Attribute" . But this is not appreciated.
Expected Result
This is a sample Paragraph Sample Attribute
Actual output
This is a sample Paragraph
Is there any other way I set value in a template?
javascript angularjs
Tom hulme
source share