什么是单页的应用程序使用Disqus最好的方法? 我看到角度js文档已成功实现它。什么是单页的应用程序使用Disqus最好的方法?
目前我们的做法看起来是这样的在我们的AngularJS应用程序,但它似乎不太稳定,难以测试,并加载错误的线程ID(同一个线程被加载几乎无处不在)。
'use strict';
angular.module('studentportalenApp.components')
.directive('disqusComponent',['$log', '$rootScope', function($log, $rootScope) {
var _initDisqus = function _initDisqus(attrs)
{
if(window.DISQUS) {
DISQUS.reset({
reload: true,
config: function() {
this.page.identifier = attrs.threadId;
this.disqus_container_id = 'disqus_thread';
this.page.url = attrs.permalinkUrl;
}
});
}
else
{
$log.error('window.DISQUS did not exist before directive was loaded.');
}
}
//Destroy DISQUS bindings just before route change, to properly dispose of listeners and frame (postMessage nullpointer exception)
$rootScope.$on('$routeChangeStart', function() {
if(window.DISQUS) {
DISQUS.reset();
}
});
var _linkFn = function link(scope, element, attrs) {
_initDisqus(attrs);
}
return {
replace: true,
template: '<div id="disqus_thread"></div>',
link: _linkFn
};
}]);
我怀疑这不是您的指令问题,但无论如何,每个评论都会在每个评论部分的每个页面上呈现我的应用。 我传递唯一标识符作为属性,并使用ng-bind-ready,因为我使用异步数据加载。我也检查过这个指令,看看我的标识符。 我使用没有HTML5模式的角路由,没有任何哈希前缀(只有#号)。 你有什么想法如何解决它?我在你的指令github页面上添加了一个问题。 – 2014-02-24 23:35:34
好的,我们可以在GitHub问题跟踪器上继续此操作。对于任何阅读谁有同样的问题,这里的链接:[https://github.com/michaelbromley/angularUtils/issues/1](https://github.com/michaelbromley/angularUtils/issues/1) – 2014-02-25 07:49:27
显示错误:'TypeError:无法读取未定义的属性'disqus_shortname' – marukobotto 2016-10-01 14:57:04