【问题标题】:Angularjs Skype URI "onclick" issueAngularjs Skype URI“onclick”问题
【发布时间】:2014-04-30 07:21:57
【问题描述】:

我正在尝试在网站上实现Skype Button 我正在使用Angularjs

Skype API 提供的代码如下

</script>
<div id="SkypeButton_Call_mike_1">
  <script type="text/javascript">
    Skype.ui({
      "name": "dropdown",
      "element": "SkypeButton_Call_mike_1",
      "participants": ["mike"],
      "imageSize": 32
    });
  </script>
</div>

我使用angularjs,所以mike 伪来自我的角度model(控制器)。

$scope.user.skypePseudo = "mike"

那么当我改变时

"participants": ["mike"]

到

"participants": ["{{user.skypePseudo}}"] 

它会抛出这个错误

Interpolations for HTML DOM event attributes are disallowed.  Please use the ng- versions (such as ng-click instead of onclick) instead.

错误很明显,这意味着我不能使用 onclick,应该改用 ng-click。

我尝试通过将所有onclick 替换为ng.click 来修改skype-uri.js,但出现了一些编译错误。

在我之前有没有人经历过这种情况?我怎样才能让它工作?

问题可以这样问:有没有办法强制 angular 接受onclick

【问题讨论】:

    标签: javascript jquery angularjs skype skype-uri.js


    【解决方案1】:

    我认为实现这一目标的最佳方法是创建一个新指令:

    angular.module("yourApp")
    .directive("skypeUi", function() {
        return {
            restrict: "E",
            template: "<div></div>",
            replace: true,
            scope: {
                participants: "="
            },
            link: function(scope, element, attrs){
                Skype.ui({
                    "name": "dropdown",
                    "element": attrs.id,
                    "participants": scope.participants,
                    "imageSize": 32
                });
            }
        };
    });
    

    所以你可以这样使用;

    <skype-ui id="SkypeButton_Call_mike_1" participants="participants">
    </skype-ui>
    

    最后在你的控制器中:

    $scope.participants = ["mike"];
    

    【讨论】:

    • 复制粘贴你的代码,它就像一个魅力!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 2013-07-24
    • 2011-08-24
    • 1970-01-01
    相关资源
    最近更新 更多