I have a scenario where I am using one app controller to call a model window and need to pass data from the $mdDialog model window to the app controller. How can I achieve this?
//parent Controller
class appCtrl implements IappSettings {
public displayItems = [some array items];
public sortingItems = [some array items];
public backItems: string;
}
dopopup(event) {
this.$mdDialog.show({
controller: appCtrl,
controllerAs: '$ctrl',
template: '<displayArrayCtrl on-save="$ctrl.onSave(displayColumns)"></displayArrayCtrl>'
});
}
onSave(displayColumns) { //on button click on child controller
this.backItems = displayColumns; //Using {{$ctrl.keyItems}} in app.html page but it's giving me empty string
}
//Child Controller
class displayArrayCtrl {
saveData = function (selectedFields: any, sortSelectedFields: any) { //on button click on parent controller
this.onSave({displayColumns: this.displayColumns}); //calling parent controller event
}
}
class displayArrayOptionsOptions implements ng.IComponentOptions {
public controller: any;
public templateUrl: string;
public bindings: any;
constructor() {
this.controller = displayArrayCtrl;
this.templateUrl = 'page.html';
this.bindings = {
onSave: '&',
displayItems: '<',
sortingItems: '<'
};
}
angular.module('app')
.component('displayArrayCtrl', new displayArrayOptionsOptions());
The communication between the child and parent controllers is working fine, however, there seems to be an issue with how the variable assignment is being handled.