考虑到我有两个视图,view1和view2。
我从View1中的API获取数组。从那里开始,我试图通过跟踪$ index来查看view2并动态渲染view2,因为数组中有对象。 (这就是预期的行为)
在 HTML 中,我将按以下方式从view1转到view2:
观看1:
<div ng-repeat="factor in vm.testDetails.factor track by $index">
<button ui-sref="app.factor_stans({factorName: factor.name, factorId: factor._id })" class="factorNamePress" > {{factor.name}} </button>
</div>
视图2:
<div ng-click="vm.goToPrevDim()">Go to previous dimension</div>
<div ng-click="vm.goToNextDim()">Go to next dimension</div>
<label for="low_stan">Number of stens in low</label>
<input type="number" name="low_stan" ng-model="vm.low_stan">
</div>
<button ng-click="vm.fillStans()"> Submit Query</button>
<h1>Low Stan Fills</h1>
<div ng-include="vm.stanFills.lowStanFills">
<!--This contains some input felds that I want to attach with this given url -->
</div>
我只会发布以下控制器的相关部分:
vm.fillStans = fillStans;
vm.goToPrevDim = goToPrevDim;
vm.goToNextDim = goToNextDim;
function selectedItemChange(item) {
console.log("This is the item that I am gonna send to the backend");
console.log(JSON.stringify(item));
AdminService.getDetailsOfOneTest(item.value).then(function (response) {
console.log("This is the details of the test");
vm.testDetails = response.data;
vm.finalObj = vm.testDetails.factor[vm.dimensionIndex.index]
console.log(vm.testDetails);
console.log("End of details of test");
goToNextDim();
goToPrevDim();
// $location.path('app.factor_stans');
})
}
function goToNextDim() {
vm.dimensionIndex.index = vm.dimensionIndex.index + 1;
vm.finalObj = vm.testDetails .factor[vm.dimensionIndex.index];
console.log(vm.finalObj);
}
function goToPrevDim() {
vm.dimensionIndex.index = vm.dimensionIndex.index - 1;
vm.finalObj = vm.testDetails .factor[vm.dimensionIndex.index];
console.log(vm.finalObj);
}
预期的行为是来自view2的,它应该能够在我点击按钮时转到下一个因素或上一个因素,但它不会。
我花了一整天的时间试图解决这个问题,我正在画一个空白。请仔细研究,看看我是否遗漏了什么。