AngularJS: 如何更新 $scope 属性
AngularJS: How can I update the $scope property
我在 $scope 上有一个对象,它指示 "next screen" 应用程序在更新后运行(我处于类似向导的多屏幕新表单中)并且在显示每个屏幕时,我想在边栏中显示当前和所有后续屏幕 -- 便于用户返回以进行更改,但不允许 him/her 通过不显示未来屏幕来跳过步骤。
当然,它必须是动态的,因为不同类型的贷款屏幕顺序会发生变化。
我的问题 -- 在当前屏幕的控制器中,如何将状态更改为 true 并使视图识别更改? (LoDash 可用)
这是 $scope.screens(对象数组)的一部分:
[
{
"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
}
]
我从农民屏幕转到申请人屏幕,我可以从状态 URL 提醒 "applicant" -- 该值应该可以用于 "find" $scope.screens 中的正确对象,但我无法弄清楚
这是 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);
});
};
});
})();
可能是因为根据您上面引用的屏幕数组,'currScreen' 未定义?我的意思是“$scope.screens[0].currScreen”不存在,因此您不能分配“$scope.screens[0].currScreen.status = 1”。
我在 $scope 上有一个对象,它指示 "next screen" 应用程序在更新后运行(我处于类似向导的多屏幕新表单中)并且在显示每个屏幕时,我想在边栏中显示当前和所有后续屏幕 -- 便于用户返回以进行更改,但不允许 him/her 通过不显示未来屏幕来跳过步骤。
当然,它必须是动态的,因为不同类型的贷款屏幕顺序会发生变化。
我的问题 -- 在当前屏幕的控制器中,如何将状态更改为 true 并使视图识别更改? (LoDash 可用)
这是 $scope.screens(对象数组)的一部分:
[
{
"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
}
]
我从农民屏幕转到申请人屏幕,我可以从状态 URL 提醒 "applicant" -- 该值应该可以用于 "find" $scope.screens 中的正确对象,但我无法弄清楚
这是 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);
});
};
});
})();
可能是因为根据您上面引用的屏幕数组,'currScreen' 未定义?我的意思是“$scope.screens[0].currScreen”不存在,因此您不能分配“$scope.screens[0].currScreen.status = 1”。