Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在指令模板中调用函数_Javascript_Angularjs_Angularjs Directive_Angularjs Controller - Fatal编程技术网

Javascript 在指令模板中调用函数

Javascript 在指令模板中调用函数,javascript,angularjs,angularjs-directive,angularjs-controller,Javascript,Angularjs,Angularjs Directive,Angularjs Controller,我有这样的指令 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)">

我有这样的指令

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

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

缺少独立作用域函数绑定

提琴手样本: `

angular.module('myApp',[]).controller('myCtrl',function($scope){
$scope.makeitTodo=函数(消息){
控制台日志(消息);
}
}).directive('clipChat',function(){
返回{
限制:“E”,
作用域:{done:'&'},
模板:“”+
“点击我”
}
});;

`缺少隔离作用域函数绑定

提琴手样本: `

angular.module('myApp',[]).controller('myCtrl',function($scope){
$scope.makeitTodo=函数(消息){
控制台日志(消息);
}
}).directive('clipChat',function(){
返回{
限制:“E”,
作用域:{done:'&'},
模板:“”+
“点击我”
}
});;
`

app.controller('ChatCtrl',  ["$scope",function($scope){
 $scope.makeitTodo = function(a){
  alert(a);
}
}])
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>'
    }
});;