通过在angularjs中使用ng-click来编写事件onclick

时间:2016-06-20 16:45:14

标签: angularjs

我想为对象设置事件// This is C++ code // Define f(int,char,float) in some C++ module: extern "C" void f(int i, char c, float x) { // ... } ,而不是像jQuery语法那样使用onclick

ng-click

我的问题是,有没有办法在angularjs中编写事件<button>Click me</button> <script> $('button').click(function () { alert('Hello World!') }); </script>

我不想这样使用:

onclick

我想在html中隐藏信息<button ng-click="sayhello()">Click me</button> angular.module('myModule', []).controller('myController', function ($scope) { $scope.sayhello = function () { alert('Hello World!'); }; });

2 个答案:

答案 0 :(得分:1)

尝试self.parent()

angular.element

相同的Jquery代码:

var ele = angular.element('button');

Demo

答案 1 :(得分:0)

<button click-me>Click me</button>

angular.module('myModule')
  .directive('clickMe', function(){
    return {
      link: function(scope, element){
        element.on('click', function(){
          alert('Wassup');
        })
      }
    }
})