I am using Angular in MVC Project. To change views I pass the URL to my Angular controller like this:
In my Angular Module:
var app = angular.module('myModule', ['ui.bootstrap', 'checklist-model', 'ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.pagination', 'ui.grid.selection', 'ui.grid.exporter', 'ui.grid.autoResize', 'ngRoute'])
In my MVC Controller:
public ActionResult Index()
{
ConfigureDefaultLayout();
return View("ContractorOperatorView");
//return PartialView("_ScoringSetOverride");
}
public ActionResult GetContractorPage(int companyId, string currentStatus)
{
contractorId = companyId;
ReleaseStatus = currentStatus;
string newUrl = "/SSQV4/SSQV5/Contractor/Index";
return Json(newUrl, JsonRequestBehavior.AllowGet);
}
Then in my Angular Controller:
$scope.rowDblClick = function (row) {
generalsearchService.goToContractorPage(row.entity.CompanyID, row.entity.ReleaseStatus)
.success(function (data) {
$window.location.href = data;
})
};
In my Angular service --
this.goToContractorPage = function (id, status) {
return $http.post('/SSQV4/SSQV5/Contractor/GetContractorPage', { "companyId": id, "currentStatus": status })
};
All worked fine as I was making the "contractorId" static in my MVC controller, but that is causing functionality problems. I need to pass the contractorId along with the URL to my Angular controller, but I don't know how. I tried this:
In my MVC Controller --
string newUrl = "/SSQV4/SSQV5/Contractor/Index?id=" + contractorId;
Then in my Angular controller --
$scope.contractorid = $routeParams.id;
I receive the error "routeParams is undefined". I know that there must be some way to do this, but I am clueless has to how. There is a lot of information on passing parameters from Angular to MVC, but not much on the reverse.
Any assistance is greatly appreciated!
I tried putting this in my app.js:
var app = angular.module('myModule', ['ui.bootstrap', 'checklist-model', 'ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.pagination', 'ui.grid.selection', 'ui.grid.exporter', 'ui.grid.autoResize', 'ui-router'])
$stateProvider.state('contractor', {
url: '/Contractor?contractorId',
params: {
contractorId: {
value: null,
squash: true
}
}
});
Now I get "$stateProvider is undefined" error.