Search code examples
angularjsangular-ngmodelangularjs-ng-model

Using the ng-model


I am working on a save feature using angularjs, web api and entity frame work. When the user clicks add new button I initialize some fields to default values. I have an itemDetail object and an itemPrice object. Both have an itemNo field. On the form itemDetail is updated by the ng-model. How can I also get that value in the newItemPrice()?

HTML:

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

Controller

    function newItemDetail() {
    return {
        id: 0,
        itemId: 0,
        itemNo:'',
        onHandQty: 0,
        storeListPrice: 5000.00,
        inventoried: false,
    }
}

function newItemPrice() {
    return {
        id: 0,
        itemId: 0,
        itemNo: '',
        country: 'USA',
        region: 1,
        discountPercent: 10,
        erpDeleted: false,
        deleteRemote: false,
    }
}

Solution

  • You can use the ng-change directive:

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