I have following config:
.state("addUser", {
url: "/addUser",
templateUrl: "users/add-user.html",
controller: "AddUserParent",
controllerAs: "$ctrl",
abstract: true
})
.state("addUser.General", {
url: "/General",
templateUrl: "users/add-user-general.html",
controller: "AddUser",
controllerAs: "$ctrl",
})
.state("addUser.Cost", {
url: "/Cost",
templateUrl: "users/add-user-cost.html",
controller: "AddUser",
controllerAs: "$ctrl",
})
.state("addUser.Notes", {
url: "/Notes",
templateUrl: "users/add-user-notes.html",
controller: "AddUser",
controllerAs: "$ctrl",
})
And following parent controller:
angular
.module("users")
.controller("AddUserParent", AddUserParent);
AddUserParent.$inject = ["usersSrv", "stateRouter"];
function AddUserParent(usersSrv, stateRouter) {
let $ctrl = this;
$ctrl.navigate = stateRouter.navigate;
$ctrl.user = {};
$ctrl.addUser = function() {
usersSrv.addUser($ctrl.user);
console.log($ctrl.user);
$ctrl.navigate('home');
}
}
Child controller AddUser
is just empty. When I fill in:
<input type="text" ng-model="$ctrl.user.name">
<input type="text" ng-model="$ctrl.user.location">
in addUser.General
state and switch to addUser.Cost
I lose all $ctrl.user
data. Why does it happen so? How to fix this?