After reading about dependency injection in Angular, I decided to test it out. However, when trying to inject the module, I encountered an issue with passing values from one module to another and outputting them on the console.
(Update: The issue has been resolved, but now I'm getting an error - Uncaught Error: No module: sisUser angular.min.js:18. It's not even evaluating the angular expression {{2+2}})
Let me walk you through the scenario:
Login.html
A simple Login page that asks for two text inputs - username and password, which are stored in a service called "user".
<html lang="en" ng-app="wbsislogin">
<head>
</head>
<body>
<form>
<fieldset>
<label>
<span class="block input-icon input-icon-right">
<input type="text" class="span12" ng-model="username" placeholder="Username" />
<i class="icon-user"></i>
</span>
</label>
<label>
<span class="block input-icon input-icon-right">
<input type="password" class="span12" ng-model="password" placeholder="Password" />
<i class="icon-lock"></i>
</span>
</label>
<div class="space"></div>
<div class="clearfix">
<label class="inline">
<input type="checkbox" class="ace" />
<span class="lbl"> Remember Me</span>
</label>
<button ng-click="loginbtn()" class="width-35 pull-right btn btn-small btn-primary">
<i class="icon-key"></i>
Login
</button>
</div>
<div class="space-4"></div>
</fieldset>
</form>
<script src="angular/angular.min.js"></script>
<script src="wbsis.js"></script>
</body>
</html>
Dash.html
This page simply displays the passed username and password from Login.html using the injected service.
<html lang="en" ng-app="wbsislogin">
<head>
</head>
<body>
<p>{{2+2}}</p>
<div ng-controller="ditest">
{{ usen }} {{ pasw }}
</div>
<script src="angular/angular.min.js"></script>
<script src="wbsis.js"></script>
</body>
</html>
wbsis.js
var sisUser = angular.module("wbsislogin",[]);
var wbSis = angular.module("wbsis",["wbsislogin"]); // according to solution 1
sisUser.controller("loginformCtrl",function($scope,user,$log,$location){
$scope.username = "s";
$scope.password = "test2";
$scope.loginbtn = function(){
user.usern = $scope.username;
user.passw = $scope.password;
$log.log(user.usern,user.passw);
window.location.href='http://sis_frnt.dev/app/dash.html';
}
});
sisUser.factory("user", [function($log){
var user = {
usern: '',
passw: ''
};
return user;
}]);
wbSis.controller("ditest", function($scope, $log, user){
$log.log(user.usern,user.passw);
$scope.usen = user.usern;
$scope.pasw = user.passw;
})
Please help me pinpoint where I may be going wrong in this setup.