I have this list controller,
define([
'jquery',
'app'
], function ($,app) {
app.controller("ListContacts", function($scope,$route,$http){
$http({
method: 'GET',
url:'php/listContacts.php'
}).then(function(response) {
$scope.contacts = response.data;
});
});
});
And I have this search controller as well, and I want to call the list controller inside the search if query !== undefined
define([
'jquery',
'app'
], function ($,app) {
app.controller("SearchContacts", function($scope,$route,$http){
console.log($route.current.params.query);
if($route.current.params.query !== undefined){
// call the list controller
}
$scope.search = function() {
console.log($('#frmSearchContacts').serialize());
$scope.contacts = null;
};
});
});
is it possible?
EDIT
My router,
define([
'app',
'controller/AppCtrl',
'controller/AppCtrl2',
'controller/AppCtrl3',
'controller/ListContacts',
'controller/AddContact',
'controller/UpdateContact',
'controller/SearchContacts'
], function (app) {
'use strict';
//console.log(app);
return app.config(['$routeProvider' , function ($routeProvider) {
$routeProvider
.when("/",
{
templateUrl: "js/template/app.html",
controller: "AppCtrl"
})
.when("/listcontacts",
{
templateUrl: "js/template/list.html",
controller: "ListContacts"
})
.when("/addcontact",
{
templateUrl: "js/template/add.html",
controller: "AddContact"
})
.when("/updatecontact/:id",
{
templateUrl: "js/template/update.html",
controller: "UpdateContact"
})
.when("/searchcontacts",
{
templateUrl: "js/template/search.html",
controller: "SearchContacts"
})
.when("/searchcontacts/:query",
{
templateUrl: "js/template/search.html",
controller: "SearchContacts"
})
.when("/:module/:method/",
{
templateUrl: "js/template/app.html",
controller: "AppCtrl2"
});
}]);
});