I have angular controller and its been split down into a directive.
Inside that directive the original code is attempting to call a function which still resides in the parent controller but it is claiming its not defined so Im assuming theres an issue with scope now.
Currently the code in the directive reads
setMessageState(false, true, "Problem obtaining statement");
where setMessageState is defined in the main controller - how can I enable this directive to reach out to still call that function.
EDIT: As per request some more code. this is my directive.js
(function () {
'use strict';
//Define the Controller
angular
.module("tpAccStatus")
.directive("tpAccStatusTransactionRow", tpAccStatusTransactionRow);
function tpAccStatusTransactionRow() {
return {
scope: {
trans: "=tpAccStatusTransactionRow",
accountNumber: "="
},
restrict: "A",
replace: true,
templateUrl: "tpAccStatusTransactionRow.directive.html",
bindToController: true,
controller: "tpAccStatusTransactionRowCtrl",
controllerAs: "transCtrl"
};
}
})();
with the controller as:
(function () {
'use strict';
//Define the Controller
angular
.module("tpAccStatus")
.controller("tpAccStatusTransactionRowCtrl", tpAccStatusTransactionRowCtrl);
//Inject any dependencies.
//We don't need scope injecting as we are using the Controller as Syntax
tpAccStatusTransactionRowCtrl.$inject = ["$scope", "tpAccStatusService", "nsgLogger"];
//Implement the Controller
function tpAccStatusTransactionRowCtrl($scope, tpAccStatusService, logger) {
//////////////////////// Public Interface //////////////////////////////////////////////
//Ensure there are no issues with the transient nature of the this pointer in Javascript
var vm = this;
vm.busy = false;
vm.requestStatement = requestStatement;
vm.documentLocation = "";
////////////////////////////////////////////////////////////////////////////////////////
//Activate the controller to populate the view model with any set up data
activate();
///////////////////////////////////////////////////////////////////////////////////////
//Retrieve the Administration top Level View Model from the information from the server
function activate() {
}
// get document
function requestStatement() {
if (vm.documentLocation != "") {
window.location = vm.documentLocation;
}
else {
if ((vm.trans.DocumentNumber != null || vm.trans.DocumentNumber != 'none')) {
vm.busy = true;
//setBusyState(true);
return tpAccStatusService
.requestStatement(null, null, vm.accountNumber, vm.trans.DocumentNumber)
.then(requestStatementCompleted, requestStatementErrored);
} else {
logger.error("No Accounts Selected", "Analysis Statement");
}
}
}
function requestStatementErrored(error) {
vm.busy = false;
setMessageState(false, true, "Problem obtaining statement");
}
function requestStatementCompleted(guid) {
vm.busy = false;
vm.documentLocation = "/download/" + guid;
window.location = vm.documentLocation;
}
}
})();
you can see reference to a function setMessageState() which is held in the parent controller as:
function setMessageState(showSuccess, showError, message) {
vm.showSuccessMessage = showSuccess;
vm.showErrorMessage = showError;
vm.message = message;
}