什麼是單頁的應用程序使用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