How to call ng-repeat in Angularjs using MVC .. app?

I am creating an application in AngularJS with MVC I am writing the code in AdminCtrl.js:

var adminModule = angular.module('angApp', []);
 adminModule.controller('AdminCtrl', ['$scope', '$http',
 function ($scope, $http) {
    //*****get data from  Product table
    $scope.products = {};
    GetAdmin();
    function GetAdmin() {
        $http({
            method: 'GET',
            url: '/Admin/GetAdmin',
            datatype:'HTML',
        }).success(function data() {
            $scope.products = data.result;
        })
    }
}]);

      

Now I can get data as a collection from the back using $ scope, I bind it to my view like:

<div id="divTest" ng-controller="AdminCtrl">
    <div ng-repeat="item in products">
        Prod_ID:{{item.Prod_ID}}
        Prod_Name:{{item.Prod_Name}}
        Prod_Price:{{item.Prod_Price}}
        Prod_Desc:{{item.Prod_Desc}}
    </div>
</div> 

      

in the view, I cannot link this data with ng-repeat, but this data is visible in the console. please help me figure out what I am missing.

Thanks in advance.

+3


source to share


2 answers


change

..  }).success(function data() {
                $scope.products = data.result;
            })..

      

to



..  }).success(function (data) {
                $scope.products = data.result;
            })..

      

t

   var adminModule = angular.module('angApp', []);
     adminModule.controller('AdminCtrl', ['$scope', '$http',
     function ($scope, $http) {
        //*****get data from  Product table
        $scope.products = {};
        GetAdmin();
        function GetAdmin() {
            $http({
                method: 'GET',
                url: '/Admin/GetAdmin',
                datatype:'HTML',
    //data needs to be inside bracket
            }).success(function (data) {
                $scope.products = data.result;
            })
        }

}]);

      

+1


source


I only made a small mistake, I was tied to ng-app, but in the sense that it should be tied, now it works.

my new code is like .....



   <body ng-app="angApp">
   <script src="Scripts/app/AdminCtrl.js"></script>

   <div id="alert" class="alert"></div>
   <div ng-controller="AdminCtrl">

        <div class="admin-login">
            <h2>using angularjs</h2>
            <input type="text" id="txtUserAng" placeholder="User Name" ng-model="U_Name" />
            <input type="password" id="txtPWDAng" placeholder="Password" ng-model="U_PWD" />
            <input type="button" id="login" value="login" ng-click="Login()" />

        </div>

    </div>
</div>

      

+2


source







All Articles