登录应用程序无效

时间:2014-05-06 11:16:59

标签: angularjs

这是我在Angular的第一个应用程序。我不确定为什么它不起作用。

    <body ng-controller="LoginController">
<div name="signIn" class="box-content">
<div class="box-top-content">

        <label>Username:</label><input type="text" ng-model="username" /></br> 
        </br> <label></label>Password:</label><input type="password" ng-model="password"></br>
        <button type="submit" ng-click="submit()">login</button>
    </div>

我的JS是:

var loginApp = angular.module('loginApp', []);

loginApp.factory('authFactory',function(){

var authFactory ={};


authFactory.login = function (username,password){
     if ( username == "abc" && password=="test")
         return true;
     else
         return false;

};
return authFactory;

});

loginApp.controller('LoginController', function($scope,authFactory) {

$scope.submit= function ($scope,authFactory) {
    authFactory.login($scope.username, $scope.password).then(function (status) {

           if (status) {
                 alert("not welcome");
              }
              else {
                  alert("welcome");
              }

       }); 


};



});

当我点击“提交”按钮时,没有任何反应。没有错误消息。这段代码怎么了?

1 个答案:

答案 0 :(得分:1)

您需要在工厂内返回对象:

loginApp.factory('authFactory',function($http){
    var authFactory ={};
    authFactory.login = //...

    return authFactory;  //Here it is
});