如何从指令中调用函数? 当调用GetAllActivityActionDetails方法时,函数不会触发。 控制器功能:
function GetAllActivityActionDetails() {
alert("GetAllActivityActionDetails");
}
指令是:
app.directive("bwUpload", ['$log', '$http', function ($log, $http) {
return {
scope: { project: "=", activity: "=", action: "=", document: "=" },
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
$log.log('onload.byteLength: ' + loadEvent.target.result.byteLength);
scope.$apply(function () {
var p = 'project_id=' + scope.project._id + '&activity_id=' + scope.activity._id +
'&action_name=' + scope.action.name + '&document_id=' + scope.document._id
var config = {
url: 'baf/DocumentUpload?' + p,
method: 'POST',
headers: { 'Content-Type': 'application/octet-stream' },
data: new Uint8Array(loadEvent.target.result),
transformRequest: []
};
$http(config).then(
function (resp) {
var response = resp.data;
$log.log("DocumentUpload response (fileName, length): " + response.fileName + ", " + response.length);
alert('Document Uploded.');
//bwGlobals.refreshView()
alert(scope.activity._id);
//GetAllActivityActionDetails(scope.activity._id);
scope.$apply("GetAllActivityActionDetails()");
alert("GetAllActivityActionDetails");
},
function (errResponse) { alert(errResponse); }
);
});
}
reader.readAsArrayBuffer(changeEvent.target.files[0]);
});
}
}
}]);
我想调用GetAllActivityActionDetails()表单指令,但它无法正常工作
答案 0 :(得分:0)
虽然这不是角度模式的好习惯,但您可以在全局中创建函数并使用窗口从指令调用。
var GetAllActivityActionDetails = function () {
alert("GetAllActivityActionDetails");
}
然后在指令中触发它:
window.GetAllActivityActionDetails();