在AnguarJs中编辑输入值后,不更新ng-model值?

时间:2017-09-17 09:25:54

标签: angularjs firebase

enter image description here我必须创建用户编辑产品详细信息的基本CRUD应用程序,但在我的情况下输入值已填充但编辑后的值,编辑后的值不显示在控制器中如何修复这个问题

//editProductDetail function for edit the product detail
	$scope.editProductObj = [];
  $scope.editProductDetail = function(productObject) {
		$scope.editProductObj  = productObject;
	}
  

//call  udpateProductDetailc function for update the detail
$scope.item          = {};
$scope.getProductKey = [];
$scope.udpateProductDetail = function(index, productObject) {
		var data = {
	 		productId     : $scope.item.pid,
	 		productName   : $scope.item.pname,
	 		brandName     : $scope.item.bname,
	 		productPrice  : Number($scope.item.price)
	 	}

		$scope.getProductKey  = productObject.key;
		var db     = firebase.database();
		var sellerProduct = db.ref("sellerProduct"); 
  }
<div ng-repeat="list in productArray">
  <a href="#" class="fa fa fa-group" 
    onclick="document.getElementById('editProduct').style.display='block'"       ng-click="editProductDetail(list)">
   </a>
   <div>
   
<div class="w3-container"> 
    <div class="col-sm-9">
      <div class="w3-container">
          <label>Enter Prduct Id</label>
          <input type="text" name="text" ng-model="item.pid"
          value="{{editProductObj.productId}}"><br>
           <label>Enter Brand Name</label>
          <input type="text" name="text" ng-model="item.bname"
          value="{{editProductObj.brandName}}"><br>
           <label>Enter Product Name</label>
          <input type="text" name="text" ng-model="item.pname"
            value="{{editProductObj.productName}}"><br>
           <label>Enter Product Price</label>
          <input type="text" name="text"  ng-model="item.price"
          value="{{editProductObj.productPrice}}"><br>
      </div>
    </div>
 </div>
<div class="w3-btn w3-blue" ng-model="wholeItem"
    ng-click="udpateProductDetail($index, editProductObj)">Udpate
</div>

2 个答案:

答案 0 :(得分:1)

尝试初始化“$ scope.item”,如下所示:

$scope.item = {pid: "",bname:"",pname:"",price:""};

答案 1 :(得分:0)

更改内容时,input中的更改内容为ng-model。您无需使用valueng-value

所以你的HTML应该是这样的:

<div class=""> 
    <div class="col-sm-9">
      <div class="w3-container">
          <label>Enter Prduct Id</label>
          <input type="text" name="text" ng-model="item.pid"><br>
           <label>Enter Brand Name</label>
          <input type="text" name="text" ng-model="item.bname"><br>
           <label>Enter Product Name</label>
          <input type="text" name="text" ng-model="item.pname"><br>
           <label>Enter Product Price</label>
          <input type="text" name="text"  ng-model="item.price"><br>
      </div>
    </div>
 </div>