我有两个部分,每个部分都有许多ng-model。
partial1.html
<input ng-model="A" /> //user enters a
<input ng-model="B" /> //user enters b
<input ng-model="C" /> //user enters c
<button ng-click="SavePartialOne()> Save and go to partial 2 </button>partial2.html
<input ng-model="P" /> //user enters p
<input ng-model="Q" /> //user enters q
<input ng-model="R" /> //user enters r
<button ng-click="SavePartialTwo()> Save and go to partial 3 which is by now populated from all the data filled in partial1 and 2 </button>partial3.html
<input ng-model="X" /> //angular binds this to auto-populate data from A input box
<input ng-model="Y" /> //auto-populate data from A and P input box
<input ng-model="Z" /> //auto-populate slightly modified data from A input box ilke a is changed to a+1我需要做的是在所有的分音中提到注释。在这里帮助我使用app.js,例如,我将如何访问和返回此数据?
发布于 2015-09-29 20:53:46
首先,将所有ng-model更改为在对象中可用,如下所示:
<input ng-model="dataModel.A" />
<input ng-model="dataModel.B" />
<input ng-model="dataModel.C" />
<button ng-click="SavePartialOne()> Save and go to partial 2 </button>
<input ng-model="dataModel.P" />以此类推,以便我们可以在SavePartialTwo方法中轻松读取和组织这些数据的值,请执行以下操作:
$scope.dataModel = {};
$scope.SavePartialTwo = function() {
$scope.dataModel.X = $scope.dataModel.A;
$scope.dataModel.Y = $scope.dataModel.A + ' ' + $scope.dataModel.P;
$scope.dataModel.Z = $scope.dataModel.Z + 1;
// Then display your 3rd partial
};https://stackoverflow.com/questions/32844242
复制相似问题