angularjs - 如何在自定义指令内单击按钮时调用指令

标签 angularjs angularjs-directive

嗨,我正在研究 angularjs 的自定义指令。我只想知道当我单击按钮时如何调用指令。请建议我如何实现这一目标。

谢谢

最佳答案

<div ng-controller="ctrl">
    <mydirc></mydirc>
    <button ng-click="clickMe()">call clickMe()</button>
</div>

app.directive('mydirc', function() {
    return {
        restrict: 'E',
        replace: true,
        template: '<div></div>',
        link: function($scope, element, attrs) {
            $scope.clickMe= function() {
                alert('inside click');
            }
        }
    }
});

关于angularjs - 如何在自定义指令内单击按钮时调用指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24817223/

相关文章:

javascript - AngularJS指令模板不执行Javascript

javascript - 删除照片时 ng-src 更新但 src 不更新

javascript - 当使用 $compile 以编程方式创建指令时,如何调用链接函数?

javascript - AngularJS - 包装指令

javascript - Angular JS 中的堆叠条形图(高图表)

javascript - 构建 $http.get 请求...错误

javascript - 如何在 Angular 中生成独立的 HTML 页面

javascript - 如何在 angular1 中附加动态 html 和动态数据?

附加变量的 Angularjs 路由

javascript - 将日期从一种格式转换为另一种格式 - AngularJS