Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Just stuck up with a problem,
I Have a module, and i have created two controllers under it,

JavaScript
var myApp = angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope,$rootScope) {
$scope.nam=angular.copy($rootScope.name);
}
function MyCtrl1($scope,$rootScope) {
    $rootScope.name = [{"IPNo":"0000001","IPDate":"14/03/2016",IPTime:"1127",IPPatId:"267",IPPatName:"AANTAR MASOUD  ABDULLAH  AL JAMOODI     ",IPPatGender:"Male",IPPatAge:"        85 Y",PRemarks:"",IPConsName:"DR.AYSHA     "}]
      $scope.own = [{"IPNo":"0000001","IPDate":"14/03/2016",IPTime:"1127",IPPatId:"267",IPPatName:"AANTAR MASOUD  ABDULLAH  AL JAMOODI     ",IPPatGender:"Male",IPPatAge:"        85 Y",PRemarks:"",IPConsName:"DR.AYSHA     "}]
}


The problem is the ng repeat not working with the section under the controller MyCtrl

and here is the markup

HTML
<div ng-controller="MyCtrl">
 <div ng-repeat="name in nam">
 {{name.IPDate}}
 </div>
</div>
<div ng-controller="MyCtrl1">
<div ng-repeat="own in own">
 {{own.IPDate}}
 </div>
</div>


What I have tried:

The ng repeat is not working in a scenario.
Posted
Updated 14-Mar-16 7:08am

1 solution

Hey Manukpk,

please check the calling sequence of your html code. Unless you call the constructor of your MyCtrl1, $rootScope.name is undefined.

When I switch the order in your HTML like this...

HTML
<body ng-app="myApp">
    <div ng-controller="MyCtrl1">
        <div ng-repeat="own in own">
            {{own.IPDate}}
        </div>
    </div>
    <div ng-controller="MyCtrl">
        <div ng-repeat="name in nam">
            {{name.IPDate}}
        </div>
    </div>

</body>


... I get the following output:

14/03/2016
14/03/2016


As a quick side note: nam is not the best variable name and ng-repeating over own in own is nasty variable shadowing. Do yourself a favor and get rid of this ;)

Hope this helps,
–Konstantin
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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