0
angular
    .module('ApplicationOne',[])
    .controller('myControllerOne', function($scope){
        $scope.name = "Luther";
        $scope.fname = "Martin";
        $scope.ed = "B.TECH";
    });
    angular
    .module('App2',[])
    .controller('myControllerTwo', function($scope){
        $scope.name = "Juliet";
        $scope.fname = "Willium";
        $scope.ed = "BSC"; 
    });

In my localhost, the first module is working fine, but problem with the second module, I can't catch it even I referred official documentation of AngularJS, Please give some brief about this, I'm very interested to learn 'ng-script', And i'm a starter on this topic.Click to see the result in my localhost Here's the link of my jsfiddle: https://jsfiddle.net/daranaveen007/dt256cep/

  • What is your goal here? There can only be a single root module for an application, so whichever your root module is, if you want to use components from the second module, you will need to list it as a dependency. – Blunderfest Aug 04 '16 at 13:49
  • Where is your app declaration ? – Weedoze Aug 04 '16 at 13:51
  • Ok.. Now I have stopped at MODULES, not yet known about the Dependencies. I'm in starting stage in AngularJS. So, That's why I'm looking forward of this. Ok. Thanks for your response. – Dara Naveen Kumar Aug 04 '16 at 13:52
  • I have declared app at each div, ng-app=' ' like that.. please refer my JSFiddle. – Dara Naveen Kumar Aug 04 '16 at 13:53
  • have a look at this: http://stackoverflow.com/questions/18571301/angularjs-multiple-ng-app-within-a-page – Gatsbill Aug 04 '16 at 13:56
  • Yes, I have already seen the link you posted before. But found that it is wrong way to assign the declaration of a module to a js variable. I found it in official documentation of Angular JS. You can just find it here https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#modules – Dara Naveen Kumar Aug 04 '16 at 14:08

1 Answers1

0

Add the first module as a dependency to the second module.

angular.module('App2',['ApplicationOne'])

Although this is useful, only if your first module declares services or components which the second module can use. As far as controllers are concerned, they should be added to single root module.

In your case, you do not need two modules. A single module with one controller is sufficient. Instead you need array of persons.

angular.module('ApplicationOne', [])
.controller('myControllerOne', function($scope, $rootScope) {

  $scope.message = "Hello World!";

  $scope.persons =[{
    name: "Luther",
    fname: "Martin",
    ed: "B.TECH"
  },{
    name: "Juliet",
    fname: "Willium",
    ed: "BSC"
  }]

});

HTML:

<div ng-app="ApplicationOne" ng-controller="myControllerOne">
<div class="row" ng-repeat="person in persons">
  <div class="col-md-6 col-md-offset-3">
    <table class="table">
      <tr>
        <td>Name:</td>
        <td>
          <input type="text" class="form-control" ng-model="person.name"> </td>
      </tr>
      <tr>
        <td>Fathers name:</td>
        <td>
          <input type="text" class="form-control" ng-model="person.fname">
        </td>
      </tr>
      <tr>
        <td>Ed.Qual:</td>
        <td>
          <select class="form-control" ng-model="person.ed">
            <option value="MCA">MCA</option>
            <option value="M.TECH">M.TECH</option>
            <option value="B.TECH">B.Tech</option>
            <option value="BSC">BSC</option>
          </select>
        </td>
      </tr>
      <tr>
        <td>
          <button ng-click="message = 'Good job (Magilchi).'" class="btn btn-primary btn-md"> Save </button>
        </td>
        <td>
          <p>{{ message }}</p>
        </td>
      </tr>
    </table>
  </div>
</div>

Dev Shah
  • 302
  • 1
  • 7
  • Sorry @Dev Shah sir, still it is not working as I tried in the way you told. – Dara Naveen Kumar Aug 04 '16 at 13:58
  • Sir, pls refer JS fiddle in the above link and try to help me to solve (know) about this. I can't sleep with a doubt when I'm learning something interested. Sorry for the trouble. Thank you.. – Dara Naveen Kumar Aug 04 '16 at 14:10
  • Yes, I agree with you, for now it is OK. But, What can I do when there is a need of using two modules at a time in one HTML page??? I'm not familiar with 'Dependencies" concept. Without the dependencies it is not possible to do, I'll take it easy. I'm looking for other than that. I'm not sure whether I'm asking a good question or not. but need to clarify the bubble in my way. That is why I'm asking this.. – Dara Naveen Kumar Aug 05 '16 at 08:35