1

I have a detail view and from database only single record is comming, I need to assign data to controls. below is my code

  var app = angular.module("MyProductApp", []);
        app.controller("ProductsController", function ($scope, $http) {
            var ProductID = @Html.Raw(Json.Encode(ViewData["ProductID"]));
            $http.get('/api/Products/GetProductForEditOrDetail',{params: { ProductID : ProductID }}).
            success(function(data){
                $scope.Product = data;
            }).
            error(function(data){
                alert("msg");
            });
        });

and below is html code

<div ng-app="MyProductApp" class="form-horizontal">
    <div ng-controller="ProductsController">
        <h4>Product</h4>
        <hr />
        <div class="form-group" >
            <label class="control-label col-md-2">Product Name</label>
            <div class="col-md-10">

                <input id="txtProductName" type="text" class="form-control" name="txtProductName" disabled="disabled" Value="{{Product.ProductName}}" />
                <input id="hdnProductID" type="hidden" class="form-control" name="hdnProductID" value="{{Product.ProductID}}" />
                <input id="hdnCategoryID" type="hidden" class="form-control" name="hdnCategoryID" value="{{Product.CategoryID}}" />
            </div>
        </div>
</div>
</div>

3 Answers 3

1

You should use ngModel directive

The ngModel directive binds an input,select, textarea (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.

<input ng-model="Product.ProductName" />
Sign up to request clarification or add additional context in comments.

Comments

0

ngModel is what you are looking for, read the docs !

Comments

0

You wanted to pass value with hidden fields, so ng-model would not work in that case, you could use ng-value in that case

<input id="hdnCategoryID" type="hidden" class="form-control" name="hdnCategoryID" ng-value="Product.CategoryID" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.