I am new to angularjs, and writing an application where a template(inventory.html) containing grid is opened with , it has a validate button at bottom of grid, which calls validate() to validate selected grid rows, before that i need a modal to popup and take user name as input and then process further.
my validate function is inside controller of template(i.e. inventory.html) . I have a app.js which contains routing info and controller.js which contains controllers for all templates.
My question is, if there is any way that I can open modal from validate(), take user input and proceed further without writing separate controller for modal. (I have a separate userinput.html for modal.)
(Sorry If my question is not clear. Plz help I am stuck with this and have tried many options from web)
// This is my controller
var app = angular.module('app', []);
app.controller('InventoryCtrl',['$scope','$location','$http','$modal',function($scope, $location, $http,$modal{console.log("Inside inventory ctrlr");
// Validate Function for validate button click
$scope.validate = function()
{
$scope.user = null;
$scope.build = null;
// Show modal to take user inputs for environment
var modalInstance = $modal.open(
{
controller : "inputModalCntrl",
templateUrl : "../partials/addEnvironment.html",
resolve: {
$callback: function () {
return function(param,user,build){
/* This function print value(param) dispached in modal controller */
console.log(param,user,build);
$scope.user = user;
$scope.build = build;
};
},
$send: function(){
return function(){
/* This function send param for the modal */
return {param1:"Hello Word Main"};
};
}
}
});
// This is further process of function
postdata = {};
var dlist = $scope.gridApi.selection.getSelectedRows();
postdata['dlist'] = dlist;
$http({ url: "/api/check", data: postdata, method: "POST" })
.success(function (response) { alert(response);})
.error(function () { alert('Error getting data');});
};
}]);
and this is modal controller
app.controller("inputModalCntrl", function($scope, $modalInstance, $callback, $send) {
$scope.init = function(){
/* This function print value(param) dispached in main controller */
console.log($send);
/* This send data to main controller */
$callback({param1:"Hello Word Modal", user :user, build : build});
};
});