使用ng模型

时间:2016-05-16 22:43:32

标签: angularjs angular-ngmodel angularjs-ng-model

我正在使用angularjs,web api和实体框架工作进行保存功能。当用户单击“添加新按钮”时,我会将某些字段初始化为默认值。我有一个itemDetail对象和一个itemPrice对象。两者都有一个itemNo字段。在表单itemDetail由ng-model更新。我怎样才能在newItemPrice()中获得该值?

HTML:

x    y
0   0.0023243872
815.54065   0.0021484715
1111.9492   0.0023388069
1378.9236   0.0021542402
1631.0813   0.0021254013
1927.4899   0.0023618778
2194.3323   0.0021484711
2223.8984   0.0023157364
2446.6221   0.0022868966
2490.8728   0.0023388073
2743.0305   0.0024801167
3009.7410   0.0021917303
3262.1626   0.0022955481
3306.2815   0.0021052146
3335.8479   0.0023330392
3558.5713   0.0024772326
3602.6660   0.0023474589
3825.1497   0.0022292205
4121.6904   0.0021023308
4374.1118   0.0024916520
4447.7969   0.0023935998
4640.5586   0.0022522912
4714.5371   0.0023705289
4937.0991   0.0022263369
5233.6396   0.0021773111
5262.8101   0.0024656970
5455.9673   0.0024339736
5559.7461   0.0024455092
5752.5078   0.0021167498
5752.5078   0.0027021724
5826.4863   0.0023936001
6019.4819   0.0027021721
6048.7842   0.0021686594
6271.3760   0.0024368572
6345.5889   0.0022321043
6567.9165   0.0021167498
6612.3291   0.0022205692
6835.0225   0.0027165920
7131.4312   0.0027483148
7160.6016   0.0023849490
7427.3418   0.0020042793
7457.5381   0.0022032652
7650.2212   0.0021109823
7724.2002   0.0023301556
7724.2783   0.0022090334
7724.2783   0.0021801949
7947.1040   0.0028059918
7947.1040   0.0027425468
8242.3545   0.0019927442
8243.3809   0.0029588358
8465.4980   0.0024455097
8465.4980   0.0022032652
8510.5107   0.0029213454
8539.2910   0.0022148010
8539.2910   0.0020734922
8762.1709   0.0021686594
8762.1709   0.0026070056
8762.7764   0.0028232955
8805.9531   0.0020042795
8806.0313   0.0020590730

控制器

<input type="text" name="itemNo" class="form-control" id="itemNumber" ng-model="vm.item.itemDetail.itemNo" />

2 个答案:

答案 0 :(得分:0)

看这里: How to bind 2 models to one input field in Angular?

否则,我建议您将数据结构从2个带有ID的对象更改为1个具有2个属性的对象。

function Item() {
return {
    id: 0,
    itemId: 0,
    itemNo: '',
    price: { 
        onHandQty: 0,
        storeListPrice: 5000.00,
        inventoried: false
    },
    detail:{
        country: 'USA',
        region: 1,
        discountPercent: 10,
        erpDeleted: false,
        deleteRemote: false}
    }
}

似乎你在对象中的最后一个键/值对上添加一个逗号我建议删除它们我有时候会有一些狂野的咒语

答案 1 :(得分:0)

您可以使用ng-change指令:

ng-change="vm.item.itemPrice.itemNo = vm.item.itemDetail.itemNo"