angularjs – 指令中的语法

前端之家收集整理的这篇文章主要介绍了angularjs – 指令中的语法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在YouTube上关注指令

https://www.youtube.com/watch?v=0r5QvzjjKDc

非常好,imo.顺利完成直到最后(链接).调试器告诉我

TypeError:element.click不是函数

我已经看了七个星期天的方式,我只是没有看到它与他所拥有的东西不匹配.语法错误是否会向您跳出来?

谢谢.

angular
     .module('app.directives.contactCard',[])
     .directive('contactCard',function() {
return {
    /* choices are E-Element,A-Attribute,or C */
    restrict: 'E',scope: {
        friend: '=',title: '=',},replace: true,transclude: true,templateUrl: "contactCard.html",link: function(scope,element,attrs) {
        element.click(function() {
            alert('click');
        });
    },controller: function($scope) {
        console.log($scope.friend);
    }
}
 })

解决方法

这看起来很不错,只是元素语法的一个小问题.错误表明元素上没有这样的函数(即click()).

尝试使用以下,它使用bind:

element.bind('click',function() {
   alert('click');
})

我在这里复制你的指令:http://plnkr.co/edit/SX0zwYipydVvo6EMVfzE

猜你在找的Angularjs相关文章