2016-12-21 23 views
3

时,我有一个问题的角度失败与NG-重复,这是我的代码

HTML

<div class="row"> 
 
<div class="col-sm-12"> 
 
    <div class="panel panel-default"> 
 
     <div class="panel-heading"> 
 
      <h3 class="panel-title">Insertar presupuesto</h3> 
 
     </div> 
 
     <div class="panel-body"> 
 
      <!-- Trigger the modal with a button --> 
 
      <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#seleccionarp">Buscar producto</button> 
 
      <!-- Modal --> 
 
      <div id="seleccionarp" class="modal fade" role="dialog"> 
 
       <div class="modal-dialog"> 
 
        <!-- Modal content--> 
 
        <div class="modal-content"> 
 
         <div class="modal-header"> 
 
          <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
          <h4 class="modal-title">Seleccione su producto</h4> 
 
         </div> 
 
         <div class="modal-body"> 
 
          <label for="Buscar cliente ">Buscar producto:</label> 
 
          <input class="form-control" id="buscarproducto" ng-model="busqueda[queryBy]" value="" placeholder="Buscar" /> 
 
          <div> 
 
           <table class="table table-hover"> 
 
            <tr> 
 
             <th>Descripcion</th> 
 
             <th>Color</th> 
 
             <th>Talle</th> 
 
             <th>Stock</th> 
 
             <th>Precio</th> 
 
            </tr> 
 
            <tbody ng-repeat="emp in posts | filter:busqueda"> 
 
             <tr ng-click="comprar(emp)" data-dismiss="modal"> 
 
              <td>{{emp.nombre_producto}}</td> 
 
              <td>{{emp.color}}</td> 
 
              <td>{{emp.talle}}</td> 
 
              <td>{{emp.stock}}</td> 
 
              <td>{{emp.precio | currency}}</td> 
 
             </tr> 
 
            </tbody> 
 
           </table> 
 
          </div> 
 
         </div> 
 
         <div class="modal-footer"> 
 
          <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button> 
 
         </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
      <table class="table table-hover"> 
 
       <thead> 
 
        <tr> 
 
         <th>Nombre del producto</th> 
 
         <th>Cantidad</th> 
 
         <th>Precio</th> 
 
         <th>Total</th> 
 
         <th></th> 
 
        </tr> 
 
       </thead> 
 
       <tbody ng-repeat="p in carrito track by $index"> 
 
        <input type="hidden" name="id_producto[]" value="{{p.id_producto}}" ng-model="p.id_producto" class="form-control"> 
 
        <input type="hidden" name="color[]" value="{{p.color}}" ng-model="p.color" class="form-control"> 
 
        <input type="hidden" name="talle[]" value="{{p.talle}}" ng-model="p.talle" class="form-control"> 
 
        <tr> 
 
         <td> 
 
          <input type="text" name="nombre_producto[]" ng-model="p.nombre_producto" class="form-control"> 
 
         </td> 
 
         <td> 
 
          <input type="number" name="stock[]" ng-model="p.stock" value="1" onClick="this.select();" class="form-control"> 
 
         </td> 
 
         <td> 
 
          <input type="text" name="precio[]" ng-model="p.precio" onClick="this.select();" class="form-control" value=""> 
 
         </td> 
 
         <td>{{p.stock * p.precio | currency}}</td> 
 
         <td> 
 
          <button type="button" class="btn btn-danger" ng-click="remove($index)">Eliminar</button> 
 
         </td> 
 
        </tr> 
 
       </tbody> 
 
      </table> 
 
      <h2>Total:${{total()}}</h2> 
 
      <input type="hidden" name="total_remito" value="{{total()}}"> 
 
      <button type="submit" name="button">guardar</button> 
 
     </div> 
 
    </div> 
 
</div>

AngularJS

app.controller("ctrlremitos", function($scope, $http) { 
 

 
$scope.posts = []; 
 

 
$scope.carrito = []; 
 

 
$scope.clienteasignado = []; 
 

 
$scope.clientes = []; 
 

 
$scope.busqueda = {} 
 

 
$scope.busquedaclientes = {} 
 

 
$scope.queryBy = '$' 
 

 
$scope.newPost = {}; 
 

 
$http.get(base_url + "venta/get_productos").success(function(data, timeout) { 
 
    $scope.posts = data; 
 
}).error(function(err) {}) 
 

 
$http.get(base_url + "venta/get_clientes").success(function(data) { 
 
    $scope.clientes = data; 
 
}).error(function(err) {}) 
 

 
$scope.comprar = function(_item, index) { 
 
    $scope.carrito.push(_item) 
 
} 
 

 
$scope.asignarcliente = function(_item) { 
 
    $scope.clienteasignado.push(_item) 
 
} 
 

 
$scope.remove = function(index) { 
 
     $scope.carrito.splice(index, 1); 
 
    }, 
 

 
    $scope.total = function() { 
 
     var total = 0; 
 
     angular.forEach($scope.carrito, function(p) { 
 
      total += p.stock * p.precio; 
 
     }) 
 
     return total; 
 
    } 
 

 
});

问题是,当我选择一个产品时,推动的是价值总是价值的股票,我想要的是当你这样做推动你总是将股票价值改变为1.另一件事我需要注意的是,当更改字段“stock”中的值时,在产品搜索的数组中也发生了变化,我不知道该怎么办:(我一直在努力使这项工作在许多天内都能正常工作,我希望他们会照亮路。

问候

https://github.com/outthesystem/facturacion-codeigniter

回答

2

“$ scope.total” 是一个函数,而不是一个范围变量。 因此,除非您进行明确的调用,否则双向绑定在这种情况下将不起作用。 使其工作: 对控制器和HTML进行以下更改。 控制器的变化:

$scope.total = 0; 

$scope.comprar = function(_item, index) { 
    $scope.carrito.push(_item); 
    $scope.calculateTotal(); //Make an explicit call to calculation method 
} 

$scope.calculateTotal = function() 
{ 
    angular.forEach($scope.carrito, function(p) { 
      $scope.total += p.stock * p.precio; 
     }) 
}; 

HTML变化:

<h2>Total:${{total}}</h2> 
      <input type="hidden" name="total_remito" value="{{total}}"> 

希望这有助于

+0

感谢您的帮助,但我认为我没有让自己明白,我附上了一张图片来看看会发生什么。 –

+0

http://imgur.com/a/ik79B –

2

我可以看到,不是英语在HTML页面中,但无论如果我理解你的问题就是您正在尝试推一些实际上并不在你身边的东西DOM

$scope.asignarcliente = function(_item) { 
$scope.clienteasignado.push(_item) 
} 

什么是$scope.clienteasignado ??? ;您正在显示我的实际列表被命名为$scope.posts如果是错的,所以如果这是产品的列表中它推动你需要右击它的方式

$scope.asignarcliente = function() { 
$scope.posts.push(emp); 
}  

PS这个功能也没有要求产品指正在DOM你只是定义按钮

<button type="submit" ng-click="asignarcliente()" class="btn btn-default" data-dismiss="modal">Cerrar</button> 

我希望我操纵右边的项目,我希望它为你的作品

+0

感谢您的帮助,但我认为我没有让自己明白,我附上了一张图片,看看会发生什么。 –

+0

http:// imgur。com/a/ik79B –

+0

用于其他推送,其中选择了客户端 –