小编use*_*026的帖子

AngularJS - 将函数传递给指令

我有一个例子angularJS

<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>
Run Code Online (Sandbox Code Playgroud)

我想当我点击按钮时,会出现警告框,但没有任何显示.

谁能帮我?

angularjs

156
推荐指数
5
解决办法
14万
查看次数

标签 统计

angularjs ×1