I have my main app controller:
var betsApp = angular.module('betsApp', ['ngRoute']);
betsApp.config(function($routeProvider, $locationProvider)
{
$routeProvider.when('/', {templateUrl: 'pages/loginView.html'})
.when('/login', {templateUrl: 'pages/loginView.html'});
});
betsApp.controller('appCtrl', function($scope)
{
});
Here is the index.html:
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/controllers/loginController.js"></script>
<script src="js/services/loginService.js"></script>
<script src="js/controllers/AppController.js"></script>
<head>
<title>Bets Application</title>
</head>
<body ng-app="betsApp" ng-controller="appCtrl">
<div class="container">
<div ng-view></div>
</div>
</body>
</html>
and I have this loginView.html which is partial:
<div ng-controller="loginController">
<h1>Login</h1>
<hr>
<form>
<div class="form-group">
<input type="email" ng-model="credentials.email" value="{{credentials.email}}">
</div>
<div class="form-group">
<input type="password" ng-model="credentials.password" value="{{credentials.password}}">
</div>
<div class="form-group">
<input type="button" value="Login" ng-click="doLogin()" class="btn btn-primary">
</div>
</form>
</div>
Here is the loginController.js:
function loginController($scope, $http, Login)
{
$scope.credentials =
{
email: '[email protected]',
password: 'vlad1q'
};
$scope.doLogin = function()
{
alert();
Login.doLogin($scope.credentials)
.success(function(response)
{
if(response.response == 'success')
{
alert(response.data);
}
})
.error(function(error)
{
alert(error);
});
}
}
My question is: is it possible to connect the loginView with the loginController? I wish the login controller be in a separate file?
Note:
For now I am getting an error while using the code as described above, here is the error:
https://docs.angularjs.org/error/$injector/unpr?p0=LoginProvider
Note 2
I want to encapsulate as much as possible login view!