my guess is that Angular has no knowledge of the template, you need to manually compile it or preferably, use the template key when creating the directive.
I modified your snippet here, but basically it boils down to:
mainApp.directive('mainContainer', function($parse){
return {
template: '<h1>{{ lowerString | CapFirst }}</h1>',
link: function(scope, elem) {
scope.lowerString = 'lol';
}
};
});
Edit
As requested, here is an alternative snippet that uses the $compile
service:
mainApp.directive('mainContainer', function($compile){
return function(scope, elem) {
var lowerString = 'lol';
var html = $compile('<h1>{{ "' + lowerString + '" | CapFirst }}</h1>')(scope);
elem.append(html);
};
});
This could also work if you used $interpolate
instead of $compile
. The benefit of using $compile
is that if you were using a template with bindings to the scope, $compile
would properly bind the scope to the template, whereas $interpolate
would not.