使用控制器访问和修改不同部分的数据
access and modify data of different partials using controller?
我有两个偏导数,每个偏导数都有许多ng模型。
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在这里,即我将如何访问和返回这些数据?
首先,更改所有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
};
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 在VanillaJS中模拟模型双向数据绑定
- CSS-如何定位内容数据标题
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 序列化数据属性中对象的最可靠方法
- 如何将JSON数据导入我的ejs模板
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 画布数据到图像
- 如何使用javascript格式化同一类表列中的数据
- 数据表中的fnAddData()添加到同一行,而不是添加到新行
- JSON数据的一部分被解释为对象,而类似的部分则被解释为数组:为什么
- JQuery DataTables合并同一行数据
- jQuery数据表头部与垂直滚动不对齐
- 根据部分列数据更改表行的背景颜色
- javascript中同一类(对象)中的静态和非静态数据