Angularjs – $state.go is not working from separate controller


Here is my Code

.state('home', {
url: "/home",
templateUrl: "views/home.tpl.html",
.state('test', {
url: '/test',
templateUrl: "views/test/dashboard.tpl.html",


My modal view in index.html page is

<div class="modal-body" ng-controller="userController">
    <form ng-submit="login()" >
        <div class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <input type="text" class="form-control" id="exampleInputEmail1" ng-model="" placeholder="Enter email">
        <div class="form-group">
        <label for="exampleInputPassword1">Password</label>
        <input type="password" class="form-control" id="exampleInputPassword1" ng-model="user.password" placeholder="Password">
        <button type="submit" class="btn btn-default">Sign In</button>

My userController function is

$scope.login = function(){

     if($"xxxx" && $scope.user.password=="123456"){




Angular js is throwing error as

TypeError: undefined is not a function
at l.$scope.login (http://localhost/yyy/scripts/controllers/userController.js:15:19)
at ib.functionCall

The state is not transferred. Please let me know where i am wrong

Best Solution

Thanks to everyone. I found my mistake.

Earlier it was

myApp.controller('userController',['$scope', '$http','$rootScope','$stateParams', '$state', function ($scope,$http,$rootScope,$state, $stateParams)

and changed to

myApp.controller('userController',['$scope', '$http','$rootScope','$state', '$stateParams', function ($scope,$http,$rootScope,$state, $stateParams)

The injection of stateParams and state were not in order and that threwup the error.