在指令模板中调用函数

Call a function in directive template

我有这样的指令

  app.directive('clipChat', ClipChat);

function ClipChat() {
    var strfin ='*';
    var chatTemplate = '<div ng-repeat="message in newarr">   <span ng-if="message.content.slice(-1)==message.star"  ng-click="makeitTodo(message)">i <i class="fa fa-mail-forward "></i></span> '+ '</div>' ;
    var directive = {
        restrict: 'EA',
        template: chatTemplate,
        replace: true,
        scope: {
            messages: "=",
            idSelf: "=",
            idOther: "=",

        },


        link:function ($scope) {

//等等等等

我想在单击控制器内的 span 元素时调用函数 makeitTodo..

我测试过如下。

app.controller('ChatCtrl',  ["$scope",function($scope){
 $scope.makeitTodo = function(a){
  alert(a);
}
}])

但是它不起作用..请帮助我。

缺少独立作用域函数绑定

提琴手示例: https://jsfiddle.net/paka2/9yda0cLk `

angular.module('myApp', []).controller('myCtrl', function($scope) {
    $scope.makeitTodo = function(message) {
    console.log(message);
    }
}).directive('clipChat', function() {
    return {
    restrict: "E",
        scope: { done: '&' },
        template: '<input type="text" ng-model="message">'+
        '<button ng-click="done({message:message})"> click me </button>'
    }
});;

`