*Hi Sander*

*Thanks a lot for your Important advice*

*i do it as code below:*

        $scope.keypress = function (id) {
            if (window.event.keyCode == 13) {

                $http.get("/api/CustomerService/GetProduct?id=" + 
id).success(function (data) {
                    $scope.ProductName = data[0]["ProductName"];
                    $scope.sell_price = data[0]["sell_price"]
                    $scope.stock = data[0]["stock"];
                });
            }
        };

* and set view code to work with new angular code as:*

    <form method="post" ng-submit="save(); item={}">
        <table class="table table-striped table-bordered" dir="rtl">
            <tr>
                <th class="text-center">كود الصنف</th>
                <th class="text-center">إسم الصنف</th>
                <th class="text-center">الكمية</th>
                <th class="text-center">السعر</th>
                <th class="text-center">الرصيد</th>
                <th class="text-center">الإجمالى</th>
                <th></th>
            </tr>
            <tr>
                <td style="vertical-align:middle;">
                    @*@(Html.Kendo().TextBox().Name("ProductID"))*@
                    <input id="ProductID" type="text" 
ng-model="item.ProductID" ng-keypress="keypress(item.ProductID,$index)" 
ng:required ng:validate="integer" placeholder="حدد الكود" 
class="text-center form-control" style="width:100px; font-weight:bold" />
                </td>
                <td align="center" style="vertical-align:middle;">
                    <div>
                        @(Html.Kendo()
                              .AutoComplete()
                                      .Name("ProductName")
                              .DataTextField("ProductName")
                              .Events(events => 
events.Select("ProductSelect"))
                              .MinLength(1)
                              .HtmlAttributes(new { style = "width:450px; 
font-weight:bold", ng_model = "ProductName" })
                              .Placeholder("إكتب جزء من إسم الصنف")
                              .Filter("contains")
                              .Delay(1)
                              .DataSource(source =>
                              {
                                  source.Custom()
                                        .ServerFiltering(true)
                                        .ServerPaging(true)
                                        .Type("aspnetmvc-ajax") //Set this 
type if you want to use DataSourceRequest and ToDataSourceResult instances
                                        .Transport(transport =>
                                        {
                                            
transport.Read("Virtualization_Read", "Home");
                                        })
                                        .Schema(schema =>
                                        {
                                            schema.Data("Data") //define 
the 
[data](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data)
 
option
                                                  .Total("Total"); //define 
the 
[total](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total)
 
option
                                        });
                              })
                              .Virtual(v => 
v.ItemHeight(26).ValueMapper("valueMapper"))
                        )

                    </div>
                </td>
                <td align="center" style="vertical-align:middle;">
                    <input ng-readonly="item.ProductID == '' || 
item.ProductID == null" id="Quantity" name="Quantity" class="text-center 
form-control" ng-model="item.Quantity" value="1" size="4" ng:required 
ng:validate="integer" placeholder="حدد الكمية" style="width:100px; 
font-weight:bold">
                </td>
                <td align="center" style="vertical-align:middle;">
                    <input ng-readonly="true" id="SellPrice" 
class="text-center form-control" ng-model="sell_price" value="0.00" 
ng:required ng:validate="number" size="6" style="width:100px; 
font-weight:bold">
                </td>
                <td align="center" style="vertical-align:middle;">
                    <input ng-readonly="true" id="Stock" class="text-center 
form-control" ng-model="stock" value="0.00" ng:required 
ng:validate="number" size="6" style="width:100px; font-weight:bold">
                </td>

                <td class="text-center" style="vertical-align:middle; 
width:100px; font-weight:bold;">
                    {{item.SellPrice * item.Quantity | currency}}
                    @Html.TextBox("Total_Item", null, new { ng_model = 
"item.Total_Item", @style = "display:none;" })
                </td>

                <td align="center" style="vertical-align:middle;">
                    <input type="submit" name="submitbtn" value="إضافة" 
class="btn btn-primary" style="font-weight:bold;" />
                </td>
            </tr>
            <tr>
                <td colspan="7" class="text-center" style="color:red; 
font-weight:bold;">
                    <div ng-show="item.Quantity > item.Stock">رصيد الصنف لا 
يكفى</div>
                    <div ng-show="item.Quantity == 0">غير مسموح بكمية أقل 
من 1</div>
                </td>
            </tr>
        </table>
    </form>

*it works and i can get values in my view when keypress is fire, but now i 
can't get values in my api controller and i don't know how pass values from 
$Scope.sell_price as example to my controller ?*

*every thing is working if i add "item." on each ng-model as old code that 
i was use jquery with it - but when i add item.sell_price  (i mean here get 
$scope.sell_price) i got nothing ?*

*so please how can i get values in the scopes in my api controller ?*


On Thursday, June 11, 2015 at 6:08:36 AM UTC+2, Sander Elias wrote:
>
> Hi Ahmed,
>
>
> Do yourself a favor, and drop jQuery for the time you are learning Angular.
>
>
> $http.get("/api/CustomerService/GetProduct?id=" + id).success(function (
> data) {
>    angular.forEach(data, function (item) { // really? I think its highly 
> unlikely that an query by id will yield more then 1 result, and if it does, 
> you have an issue with your server!
>
>      //the lines below are all DOM manipulating. This is not how Angualr 
> works.
>      $("#Products").val(item.ProductName).trigger('change');
>      $("#SellPrice").val(item.sell_price).trigger('change');
>      $("#Stock").val(item.stock).trigger('change');
>
>
>      $("#Quantity").focus(); // for focus you should create a small 
> helper directive!
> });
>
>
>
> This can be replaced by:
> $http.get("/api/CustomerService/GetProduct?id=" + id).success(function (
> data) {
>
>    $scope.CurrentItemThatsBeingEdited = data[0]; //if the field names 
> differ between the view and the result from the server, you might need some 
> mappings.
> })
>
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to