0

I have read about the dependency injection in angular. I thought to test it. But as I inject the module, I want to pass the values from one module to another (I am outputting on console

(Edit: Solved it is giving error. Uncaught Error: No module: sisUser angular.min.js:18 It is not even evaluating the angular expression {{2+2}})

Let me explain the scenario:

Login.html

Plain simple Login for asking for two text input username and password into a service "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

Showing just the passed username and password from login.html through 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"]); // as per the 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 guide where I am doing wrong.

2
  • Try changing the load order of the js files. Move wbsis.js before angular.min.js Commented Nov 21, 2013 at 10:28
  • @CodeHater Nothing. More Errors. Uncaught ReferenceError: angular is not defined wbsis.js:1 Uncaught Error: No module: wbsis angular.min.js:18 Commented Nov 21, 2013 at 10:41

1 Answer 1

1

You need to pass the name of the module as a dependency instead of the variable name.

Change:

var sisUser = angular.module("wbsislogin",[]);
var wbSis = angular.module("wbsis",["sisUser"]);

To:

var sisUser = angular.module("wbsislogin",[]);
var wbSis = angular.module("wbsis",["wbsislogin"]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.