-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working with dynamically pulled data #87
Comments
According your description, you're actually required to have // In your controller, don't forget to inject `$templateCache`
$templateCache.put('postContent-xxx', ctrl.post.content); <!-- use `ng-include` to render post content from `$templateCache` -->
<div class="single_post_content" ng-include="'postContent-xxx'"></div> Another options is to write a new directive specialized for displaying angular.module('myApp')
.directive('singlePostContent', function (hljsService, $window) {
return {
restrict: 'A',
link: function (scope, iElm, iAttrs) {
scope.$watch(iAttrs.singlePostContent, function (content) {
if (content) {
iElm.html(content);
// You don't even require angular-highlightjs for this
var service = $window.hljs || hljsService;
service.highlightBlock(iElm[0]);
}
else {
iElm.html('');
}
});
}
};
};
}); <div class="single_post_content" single-post-content="sm.post.content"></div> Here's a working demo on Plunker: http://plnkr.co/edit/ZfB4tamhQIOLx0z9WUMH?p=preview |
Hi, for some weird reason. the directive highlighted the whole content, even though the part that's not code |
Try replacing the var service = $window.hljs || hljsService;
service.highlightBlock(iElm.find('pre > code')[0]);
// or
service.highlightBlock(iElm.find('pre')[0]); |
I've update the plunk with |
@pc035860 Hey, it still doesn't work. There was an issue from my end too. I write a post via TinyMCE editor, and when I write code with its inbuilt code tool, it adds an additional class to the I removed that in the following manner:
And then, it just styles the outer block. it isn't highlighting anything. So I inspected the element and found out that no language class has been added to my What could be the reason for this? |
Can you make a demo of your problem with plunker or something similar? |
@pc035860 Hey, so I made it work with a few tweaks, one of them really bizarre to me. First, I stored the post's content in a scope variable and passed that to the directive, like this
and then plugged that into the directive:
and it worked. I don't know why. The next issue was that it was only working for the first code block, so I changed it to this:
And this works, but I get an error in the console
Now, i can ignore that, but I really want to keep it clean. Long story short, I made it work, but I don't know how. |
Hi, I have been trying to make this work for a while now.
First of all, content is a blog post, and it is a mixed content. So there are a few
p
blocks, and thenpre code
blocks. I have manipulated the data and placedhljs
directive to thecode
tag, but it isn't working for me.and here is how I am using it
As i can see by inspecting my page that the
code
block contains the two directives, but it isn't working. There are no errors, the css is loading properly too.Why would this be happening?
The text was updated successfully, but these errors were encountered: