小编ath*_*thi的帖子

在指令模板中调用函数

我有这样的指示

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

//等等

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

我测试过如下.

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

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

javascript angularjs angularjs-directive angularjs-controller

0
推荐指数
1
解决办法
232
查看次数