I am new to Angular JS and trying to call a controller inside another controller but getting below error.
ionic.bundle.js:21157 TypeError: $controller is not a function
at new <anonymous> (http://localhost:8080/itravel/www/js/controllers.js:6:2)
at invoke (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:13277:17)
at Object.instantiate (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:13285:27)
at http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:17841:28
at self.appendViewElement (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:52255:24)
at Object.switcher.render (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:50449:41)
at Object.switcher.init (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:50369:20)
at self.render (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:52115:14)
at self.register (http://localhost:8080/itravel/www/lib/ionic/js/ionic.bundle.js:52073:10)
Am i missing anything here ?
angular.module('starter.controllers', []).controller('DashCtrl', function($scope) {
}).controller('TransportController',['$scope','$controller', function($scope, TrainService, $ionicModal, $window, $controller) {
console.log("TransportController");
$controller('ProfileController', {
$scope: $scope
})
//$scope.testFunction();
$scope.transports = [];//TrainService.all();
$ionicModal.fromTemplateUrl('templates/modal.html', {
scope: $scope
}).then(function(modal) {
if (angular.equals(typeof $window.localStorage['profile'],'undefined')) {
modal.show();
} else {
$scope.profile = JSON.parse($window.localStorage['profile']);
if (angular.equals($scope.profile.city,'undefined') || angular.equals($scope.profile.city,'')) {
modal.show();
}
}
$scope.modal = modal;
});
$scope.saveUserProfile = function() {
console.log("Saving User Profile");
console.log($scope.profile);
$window.localStorage['profile'] = JSON.stringify($scope.profile);
$scope.modal.hide();
}
}]).controller('ProfileController', function($scope, $window, $ionicModal, TrainService, $ionicHistory,$timeout) {
if (!angular.equals($window.localStorage['profile'],'undefined')) {
$scope.profile = JSON.parse($window.localStorage['profile']);
}
$scope.selectedCity = "MUMBAI";
var promise = TrainService.listCities();
promise.then(function(resp){
$scope.cities = resp.data;
})
Is this the best way to insert controller inside another controller ? I just have a common method which i want to share across all the controller kind of utility method but it calls service and using promise object it sets the value in scope variable.