Reputation: 2579
I have an object on the $scope that dictates the "next screen" for the app to go after update (I'm in a wizard-like multi-screen new form) and as each screen is displayed, I want to show the current and all subsequent screens in the sidebar -- easy to go back for the user to make changes but not allowing him/her to skip steps by not displaying future screens.
Of course, it has to be dynamic because the screen order changes for different types of loans.
My question -- in the controller of the current screen, how do I change the status to true AND make the view recognize the change? (LoDash is available)
This is a partial of $scope.screens (an array of objects):
[
{
"id": 13,
"loantype_id": 2,
"screen": "farmer",
"label": "Farmer",
"sort_order": 1,
"status": 1
},
{
"id": 14,
"loantype_id": 2,
"screen": "applicant",
"label": "Applicant",
"sort_order": 2,
"status": 0
},
{
"id": 15,
"loantype_id": 2,
"screen": "quests",
"label": "Questions",
"sort_order": 3,
"status": 0
},
{
"id": 16,
"loantype_id": 2,
"screen": "references",
"label": "References",
"sort_order": 4,
"status": 0
}
]
I move from the farmer screen to the applicant screen and I can alert the "applicant" from the state URL -- that value should be able to be used to "find" the right object in $scope.screens but I can't figure it out
This is the pertinent part of ApplicantController -- alert(currScreen) == 'applicant':
(function(){
'use strict';
angular
.module('ARM')
.controller('NewApplicantController', function(
$scope, $state, $stateParams, Loan,
AppFactory, ApplicantsFactory
){
var curr = $state.current.url;
var currScreen = curr.substring(1,curr.length);
alert(currScreen);
$scope.loan = Loan.data.data[0];
if($scope.loan.applicant_id) {
ApplicantsFactory.getApplicant($scope.loan.applicant_id)
.then(function success(rsp) {
$scope.applicant = rsp.data.data;
$scope.applicant.entity_type_id = '2';
});
} else {
$scope.applicant = { entity_type_id: '2' };
} // end if
$scope.createApplicant = function() {
ApplicantsFactory.createApplicant($scope.applicant)
.then(function(rsp){
AppFactory.patchIt('/loans/', $stateParams.loanID, {applicant_id: rsp.data.message});
AppFactory.moveToNextNewLoanScreen(currScreen, $stateParams);
});
};
});
})();
Upvotes: 1
Views: 85
Reputation: 149
Could it be because based on the array of screens that you referenced above, 'currScreen' is undefined? By this I mean '$scope.screens[0].currScreen' does not exist so you can't assign '$scope.screens[0].currScreen.status = 1'.
Upvotes: 2