share
Stack Overflowhow to assign multipul controller within a body
[+1] [1] user8518202
[2017-11-04 08:57:43]
[ angularjs ]
[ https://stackoverflow.com/questions/47109092/how-to-assign-multipul-controller-within-a-body ]

How can i assign multiple controller within a body

Html

<script src="../MyApp.js"></script>
<script src="HomeCaller.js"></script>
<body ng-app="MyApp">
    <div ng-controller="AppCtrls">{{secc}}</div>
    <div ng-controller="HomeCtrls">{{jan}}</div>
</body>

MyApp.js

(function () {
    'use strict'
    var app = angular.module('MyApp', [])
    app.controller('AppCtrls', function ($scope) {
        $scope.secc = "Hello Angular"
    })
})();

HomeCaller.js

angular.module('MyApp', [])
.controller('HomeCtrls', function ($scope) {
    $scope.jan="Hello Jan"
})
[+1] [2017-11-04 08:59:17] Igor [ACCEPTED]

Remove the [] from the module call so you do not try to re-create it. This will retrieve the existing MyApp module.

HomeCaller.js

angular.module('MyApp')
.controller('HomeCtrls', function ($scope) {
    $scope.jan="Hello Jan"
})

1