I would suggest creating two different module names, one in index.js (This will be the name of the application that you would specify in the html attribute of ng-app) and the other in contacts.js (Module name for controllers). In index.js, create dependecy for the contact. Js`. I was able to solve the problem by doing below.
Updated contacts.js Here I updated the contacts to contactsController
var myApp = angular.module('contactsController', []); myApp.controller('ContactsCtrl', function ($scope) { $scope.name = "omar"; });
Updated index.js. Here I have added ContactController as a dependency. It was easier for me to call this as app.js. This way ng-app always maps to the module name in app.js.
var myApp = angular.module('contacts', [contactsController]); myApp.config(function ($routeProvider) { $routeProvider .when('/', { controller: 'ContactsCtrl', templateUrl: '/views/show-contacts.html' }) //.when('/view2', { controller: 'MyCont', templateUrl: 'V2.htm' }) .otherwise({ redirectTo: '/' }); });
source share