0

私は私が私のコントローラ内のspan要素をクリックしたときに、関数makeitTodoを呼び出したい//などなどコール機能

この

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) { 

のようなディレクティブを持っている..

私は以下のようにテストしました。

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

しかし、それは動作していません..私を助けてください。

答えて

4

結合孤立スコープ機能は

サンプルフィドラーが欠落しています。そんなにthankuhttps://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>' 
    } 
});; 

`

+0

.. :) – athi