ng-click不会在控制器内调用我的函数

时间:2017-01-23 04:26:13

标签: angularjs ionic-framework

我是离子和angular.js的新手。我正在尝试调用一个用控制器编写的函数sayHello()。这就是我的写作方式。 在html中,

<button class="button button-large"><i class="icon ion-android-send" style="color:blue" ng-click="sayHello()"></i></button>

在controllers.js中,

.controller('CommentCtrl',function($rootScope, $scope, $state, CommentService){
     $scope.sayHello = function(){
         alert('hello');
     }
})

在应用中,

.state('app.comment',
    {
      url:'/comment',
      views:{
        'menuContent':{
          templateUrl:'templates/comment.html',
          controller:'CommentCtrl'
         }
    }
});

我仍在寻找花费数小时的错误,但我仍然面临着这个问题。谢谢和问候。

1 个答案:

答案 0 :(得分:4)

您的HTML应如下所示:

<button class="button button-large" ng-click="sayHello()"><i class="icon ion-android-send" style="color:blue"></i></button>

ng-click应该在按钮中,而不是图标。

相关问题