首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >AngularJS -将函数传递给指令

AngularJS -将函数传递给指令
EN

Stack Overflow用户
提问于 2013-08-22 18:56:25
回答 2查看 149.5K关注 0票数 164

我有一个angularJS示例

代码语言:javascript
复制
<div ng-controller="testCtrl">

<test color1="color1" updateFn="updateFn()"></test>
</div>
 <script>
  angular.module('dr', [])
.controller("testCtrl", function($scope) {
    $scope.color1 = "color";
    $scope.updateFn = function() {
        alert('123');
    }
})
.directive('test', function() {
    return {
        restrict: 'E',
        scope: {color1: '=',
                updateFn: '&'},
        template: "<button ng-click='updateFn()'>Click</button>",
        replace: true,
        link: function(scope, elm, attrs) { 
        }
    }
});

</script>
</body>

</html>

我想当我点击按钮时,警告框会出现,但什么也不会显示。

有谁可以帮我?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18378520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档