Facebook评论Ionic应用程序中的Angular Directive



我正在使用WordPress Api,并有一个简单的Facebook评论指令,它接收相应WordPress帖子的URL(即permalink)。我有一个链接到相应单个帖子的帖子列表,FB评论的问题是,当我进入单个帖子时,评论脚本不会加载。如果刷新页面,则注释框将正确显示。

我的问题是,我将如何启动关于输入新的单一视图的指令?我有一个关于使用链接的想法,用一块$watch,我只是不知道该怎么做?任何帮助都将不胜感激,谢谢。

Facebook指令:

.directive("facebookComments", function() {
return {
    scope: {
        commentsUrl: '=permalink'
    },
    template: '<div class="fb-comments" data-href="{{ commentsUrl }}" data-numposts="5"></div>'
}; });

HTML

<div facebook-comments permalink="post.url"></div>

.directive("facebookComments", function() {
return {
    scope: {
        commentsUrl: '=permalink'
    },
    template: '<div class="fb-comments" data-href="{{ commentsUrl }}" data-numposts="5"></div>',
    link: function(scope, element, attrs) {
      scope.$watch('commentsUrl', function(newValue, oldValue) {
        console.log('newValue', newValue)  
      })
    }
}; });

我在你的指令中添加了一个链接函数,其中包含一个观察者,每次url更改时都会登录到控制台!

祝好运

最新更新