-1

MY HTML PAGE

<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script src="assets/js/angular.min.js"></script>
    <script src="assets/js/app.js"></script>
</head>
<body>
    <div ng-controller="HelloController">
        <h2>Hi {{helloTo.title}}, Start learning angular js</h2>

        Enter Your Name<input type="text" ng-model="name">
        <span ng-bind="name"></span>
    </div>
    <div ng-controller="studentController">

    </div>

</body>

ANd My JS

function HelloController($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "Rahul Devan";
}

I need to use multiple controllers in the same page in a same JS file. That's why i have used controllers like this.

I am getting output like this Output I am getting

Please help to figure out the error

1 Answers1

0

Hey try this example to understand how to use multiple controllers for the same app module.

var app = angular.module('sample', []);


app.controller('first', function($scope) {
  $scope.name = 'James';

});


app.controller('second', function($scope) {

  $scope.name = 'John';
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="sample">
  <div ng-controller="first">First Controller:
    <span>{{name}}</span>
  </div>
  <div ng-controller="second">Second Controller:
    <span>{{name}}</span>
  </div>

</body>
Nikhilesh Shivarathri
  • 1,640
  • 10
  • 16