Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Folks, I am new to MVC with angularjs and facing issue while passing values from one controller in one module to other controller in other module. Here are two module ie login and myApp, so basically I want to pass data from login to myApp.

I tried with factory or service as per google search but its not working with 'ngRoute' or other services which I am using.
I highlighted the area where I am getting value need to pass to other module.


Any help or suggestion would be appreciated or mail me at vikasjbp@gmail.com,


Thanks in advance


LoginModule.js

var mylogin = angular.module("login", ['ngRoute']);

mylogin.config(function ($routeProvider) {
$routeProvider.when("/Home/Home", // Angular URL
{
templateUrl: "/Home/Home",
controller: "ValidateLoginController"
});
});

LoginController.js

mylogin.controller("ValidateLoginController", function FunctionItem($scope, $window, $http, $routeParams) {

$scope.ValidateLogin = function () {
$http.post("/Login/ValidateLogin", $scope.Login).then(function (e) {
if (e.data.Success == true) {
here am getting data in e.data and need to pass e.data to myApp

$window.location.href = "/Home/Home";
}
else {
$window.alert('Error - ' + e.data.Message + ' . Please try again!!!');
}
});
};

});


Module.js
var myApp = angular.module('myApp', ["ngRoute", "ngDialog" ]);

myApp.controller("RouteCtrl", function ($scope, $http, $location, HomeDetails, UptimerobotAPI, $rootScope, ngDialog, $timeout, $filter) {


/** create $scope.template **/
$scope.template = {
"WebServer": "/Home/WebServer",
"WebSite": "/Home/WebSites"
}


/*get server details*/
var webserver = HomeDetails.getServers();

webserver.then(function (_server) {
$scope.WebServer = _server.data;
});
/*server details end*/

/*get API data*/
var _APIdata = UptimerobotAPI.CallUpTimeRobot();

_APIdata.then(function (_data) {
var x2js = new X2JS();
$scope.WebSite = (x2js.xml_str2json(_data.data)).monitors.monitor;

var urlBase = '/Home/getAPIData';
var response = $http({
method: "post",
url: urlBase,
data: $scope.WebSite
});

response.then(function (r) {
if (r.data.Success == true) {
debugger;

}
}, function (ex) { alert(ex.data) });
});
/*API data end*/


/*popup*/
$scope.openTimed = function (_name) {

$http({
method: 'POST',
url: '/Home/getLastDownTime',
data: { url: _name }
})
.success(function (data) {
var lastdowntime = "";
var lastUPtime = "";


if (data.LastDownTime != null) {
lastdowntime = $filter('date')(parseInt(data.LastDownTime.substr(6)), 'dd-MM-yyyy hh:mm:ss');
}
else {
lastdowntime = "No Down Time recorded!!!"
}
if (data.LastUPTime != null) {
lastUPtime = $filter('date')(parseInt(data.LastUPTime.substr(6)), 'dd-MM-yyyy hh:mm:ss');
}
else {
lastUPtime = "No UP Time recorded!!!"
}


var dialog = ngDialog.open({
template: '

Last DownTime -' + lastdowntime + '

Up Since - ' + lastUPtime + '    (' + data.UPSince + ')' + '

',
plain: true,
closeByDocument: false,
closeByEscape: false
});
setTimeout(function () {
dialog.close();
}, 2000);
});

};

$scope.openConfirm = function (_name) {
debugger;
var myURL = _name;
$scope.myURL = _name;
$http({
method: 'POST',
url: '/Home/getLogbyName',
data: { _name: _name }
})
.success(function (data) {
$rootScope.LogsByName = data;
ngDialog.openConfirm({
template: 'modalDialogId',
className: 'ngdialog-theme-default'
}).then(function (value) {
console.log('Modal promise resolved. Value: ', value);
}, function (reason) {
console.log('Modal promise rejected. Reason: ', reason);
});
});
};
/*End popup*/
});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900