I have app.js file and watchExample.js file which has a controller. I am injecting this controller into my app in app.js. So I don't want to load watchExample.js file in my index.html head. Because if I have many js files, I would have to load them in my head tag. So this seems dirty to me. Why do I have to load my every extra js files, I am already injecting them in app.js? Or is there any better way to do this?
index.html
<!DOCTYPE html>
<html ng-app="watch">
<head>
<title>Angular Watch</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.min.js"></script>
<script type="text/javascript" src="app.js"></script>
<script type="text/javascript" src="watchExample.js"></script>
</head>
<body ng-controller="watchExample">
<div ng-view=""></div>
</body>
</html>
app.js
var app = angular.module("watch", ['ngRoute', 'watch-page']);
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'login.html'
})
.when('/watch',{
resolve: {
"check": function($location,$rootScope){
if(!$rootScope.loggedIn){
$location.path('/');
}
}
},
templateUrl: 'watch.html',
controller: 'watchExample'
})
.otherwise({
redirectTo: '/'
});
});
watchExample.js
var app = angular.module("watch-page", []);
app.controller('watchExample', ['$scope', function ($scope) {
$scope.counter = -1;
$scope.$watch('myText', function (newValue, oldValue) {
$scope.counter++;
if($scope.counter === 50){
alert("Yeter artık "+$scope.counter+" kere değiştirdin!");
}
$scope.oldVal = oldValue;
$scope.newVal = newValue;
});
}]);