我希望指令将值传递给回调函数(在控制器中定义)。但是,从不调用该函数,我不知道为什么。
HTML:
bool should
指令:
<input type='file' fileread success="fileUploaded(data)" name="myFile" id="myFile" />
控制器:
myApp.directive('fileread', function() {
return {
scope: {
callBack: '&success',
},
link: function (scope, element) {
scope.callBack({data: "test"});
}
};
});
FIDDLE: http://jsfiddle.net/v6r9L6g3/4/
答案 0 :(得分:0)
你的html中缺少ng-app和ng-controller 你的HTML必须是
<div ng-app="myApp" ng-controller="MyCtrl">
<input type='file' fileread success="fileUploaded(data)" name="myFile" id="myFile" />
</div>
myApp.directive('fileread', function() {
return {
scope: {
success: '&',
},
link: function (scope, element) {
scope.success({data: "test"});
}
};
});
并且
答案 1 :(得分:0)
执行代码时唯一的问题是输入必须由div包围,并带有ng-controller
指令。喜欢以下
<div ng-controller="MyCtrl">
<input type='file' fileread success="fileUploaded(data)" name="myFile" id="myFile" />
</div>
一切都很完美。