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>'
}
});;