Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ng-repaeat is not working in angular.

What I have tried:

<!DOCTYPE html>
<html>
<head>
    <script src="scripts/angular.min.js"></script>
    <script src="scripts/JavaScript1.js"></script>

    <title></title>
</head>
<body>
    <div ng-app="mymodule" ng-controller="mycontroler">

        <table>
            <thead>
                <tr>
                    <td>
                        First Name
                    </td>
                    <td>
                        Seconed Name
                    </td>
                    <td>
                        Address
                    </td>
                   
                </tr>
            </thead>
            <tbody >
                <tr ng-repeat ="employee in emp">
                    <td>
                        
                        employee.Fname
                    </td>
                     <td>
                    employee.Sname
                    </td>
                       <td>
                        employee.address
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>





/// <reference path="angular.min.js" />
var app = angular.module("mymodule", []).controller("mycontroler", function () {
    var emp = [{ Fname: "vikrant", Sname: "gupta", address: "ganj" }, {Fname:"arpit", Sname:"gupta", address:"ganj" }
    ];
    $scope.emp = emp;

});



kindly help
Posted
Updated 1-Jan-17 0:37am

1 solution

There are two mistakes in your code:

  • In your table, you have to wrap the properties between {{ and }}, for example {{employee.Fname}} instead of just employee.Fname.
  • $scope is undefined so you need to tell Angular to pass it as a parameter to your function, like this:
    JavaScript
    var app = angular.module("mymodule", []).controller("mycontroler", ['$scope', function($scope) {
      var emp = [{
        Fname: "vikrant",
        Sname: "gupta",
        address: "ganj"
      }, {
        Fname: "arpit",
        Sname: "gupta",
        address: "ganj"
      }];
      $scope.emp = emp;
    
    }]);

    Instead of passing just the function as second argument to .controller, you have to pass a list containing '$scope' and the function, taking $scope as argument.

Working demo: https://jsfiddle.net/ob2etfm7/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900