加载angularjs控制器时出错

时间:2014-03-06 00:03:43

标签: angularjs

我有以下angularjs代码。问题是,一旦包含控制器“HomeController”的页面,就不会生成警告框($ window.alert(“here”);)。

angular.module('gbuyRef').controller('UserController',function ($scope,$window,$http,$cookies)  {
        //default action
        $scope.clicked = true;
        $scope.loginError = false;
        $scope.doGreeting = function () {
            $scope.clicked = !$scope.clicked;
        };
        $scope.user = {};
        $scope.signIn = function () {
                $http({
                method : 'POST',
                url : '/signIn',
                data : $.param($scope.user), // pass in data as strings
                headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
                // set the headers so angular passing info as form data (not request payload)
                }).success(function(data, status, headers, config) {    
                if($scope.data != "failed") {
                   $scope.loginError = false;

                   $window.location.href="/static/html/home.html";
                   $cookies.fName = data;
                   $cookies.email = $scope.user.email;
                   $cookies.password = $scope.user.password;
                   $window.alert($cookies.fName)
                } else {
                  $scope.loginError = true;
                }
                }).error(function(data, status, headers, config) {
                $scope.status = status;
                $window.alert($scope.status)
                });
            };      

    $scope.signUp = function () {               
                $http({
                method : 'POST',
                url : '/signUp',
                data : $.param($scope.user), // pass in data as strings
                headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
                // set the headers so angular passing info as form data (not request payload)
                }).success(function(data, status, headers, config) {
                $scope.data = data;
                if($scope.data != "failed") {
                   $scope.loginError = false;
                   $cookies.fName = data;
                   $window.location.href="/static/html/home.html";  
                } else {
                  $scope.loginError = true;
                }
                }).error(function(data, status, headers, config) {
                $scope.status = status;
                $window.alert($scope.status)
                });
            };
    }); 

angular.module('gbuyRef').controller('HomeController',function ($scope,$window,$http,$cookies) {
    $window.alert("here");
    $scope.logOut = function() {
        $http({
            method : 'POST',
            url : '/logOut',
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
            // set the headers so angular passing info as form data (not request payload)
            }).success(function(data, status, headers, config) {
            $window.alert("here");
            $cookies.fName = "";
            $window.location.href="/static/html/login.html"
            }).error(function(data, status, headers, config) {
            $scope.status = status;
            $window.alert("error")
        });
    }
});

我的HTML如下:

<!DOCTYPE html>
<html lang="en" >
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Gbuy-Product Details</title>

    <!-- Bootstrap -->
    <link href="../css/external/css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/gbuy/gbuy.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Patua+One' rel='stylesheet' type='text/css'>
    <script src="../js/external/bootstrap/jquery-1.11.0.min.js"></script>
    <script src="../js/external/jquery-ui/ui/jquery-ui.js"></script>
    <script src="../js/external/bootstrap/bootstrap.js"></script>  
    <script src="../js/external/angular/angular.min.js"></script>
    <script src="../js/external/angular/angular-cookies.js"></script>
    <script src="../js/gbuy/gbuy.js"></script>
    <script src="../js/gbuy/gbuy-ang-controller.js"></script>
    <script src="../js/gbuy/gbuy-ang-directives.js"></script>
    <script src="../js/external/angular/angular-cookies.js"></script>
    <script>
        $(function() {
            $('#carousel_home').carousel();
        });
        $('.carousel .item').each(function(){
            var next = $(this).next();
            if (!next.length) {
              next = $(this).siblings(':first');
            }
            next.children(':first-child').clone().appendTo($(this));

            if (next.next().length>0) {
              next.next().children(':first-child').clone().appendTo($(this));
            }
            else {
              $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
            }
        });

    </script>
  </head>


<body  ng-controller="HomeController">
<header>
  <div class=" col-xs-12 header-color text-center" style="height:50px;" >
    <div class= "col-xs-1" style="height:50px;">
      <p class="gbuy-color text-left" style="font-family: 'Patua One', cursive;font-size:270%">GTEST</p>
    </div>

    <div style="padding:15px 0;">
      <div class=" col-xs-1" style="width:50px;" > <a href="#" class="login-header-color" >Deals</a></div>
      <div class=" col-xs-1" style="width:100px; "> <a href="#" class="login-header-color">Want List</a></div>

      <div class="col-xs-4">
        <form class="search-bar" role="search">
          <div class="input-group" >
            <input type="text" class="form-control  text-center" placeholder="Search Products" name="srch-term" id="srch-term" style="width:400px;height:30px; ">
            <div class="input-group-btn">
              <button class="btn btn-default" style="height:30px;" type="submit"><span class="glyphicon glyphicon-search"></span></button>
            </div>
          </div>
        </form>
      </div>

      <div class="col-xs-1 pull-right" style="margin-right:50px;">
        <div style="padding-left: 0px;padding-right: 0px;" >
           <ul class="nav pull-left">      
                <li class="dropdown text-left" style="width:100px;">
                  <a data-toggle="dropdown" class="dropdown-toggle dropdown-menu-hover-color login-header-color text-center" style="padding:0px 0px;" href="#">{{fName}}<b class="caret login-header-color"></b></a>
                  <ul class="dropdown-menu submenu-hover-color"  style="margin:0;">
                    <li><a href="#">Account</a></li>
                    <li><a href="#">Purchase History</a></li>
                    <li><a href="#">Rewards</a></li>
                    <li><a href="#">Email Subscription</a></li>
                    <li><a href="#">Refer a Friend</a></li>
                    <li><a  ng-href="#" ng-click="logOut();">Log Out</a></li>
                  </ul>
                </li>
           </ul>
        </div> 
      </div>

       <div class="col-xs-1 pull-right text-right" style="width:100px;">
        <a href="#" class="login-header-color text-right " style="margin-top:20px;">Cart</a>
        <span class="divider" style="color:#FFF;">|</span>
        <a href="#" class="login-header-color text-right "  style="margin-top:20px;">Help</a>  
      </div>
    </div>
  </div>
</header>

    <div class="col-xs-1" style="width:150pt;background-color:#A8A8A8;border:2px ridge;border-radius:25px;">
        <div class="navbar">
            <div class="container-fluid">
                <div class="nav-collapse">
                    <ul class="nav">
                        <li class="dropdown">
                            <a class= "dropdown-toggle dropdown-menu-hover-color menu-left-color"  data-toggle="dropdown" href="#">Electronics</a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a class="dropdown-level1-color menu-left-color" href= "#">Laptop</a> 
                                    <ul class=  "dropdown-menu sub-menu submenu-hover-color">
                                    <li><a href="1">Apple</a></li> 
                                        <li><a href="#">Sony</a></li> 
                                        <li><a href="#">HP</a></li>
                                    </ul>
                                </li>
                                <li><a class="dropdown-level1-color menu-left-color" href=  "#">Camera</a></li> 
                                <li><a class="dropdown-level1-color menu-left-color" href= "#">TV</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a class= "dropdown-toggle dropdown-menu-hover-color menu-left-color" data-toggle="dropdown" href="#">Home</a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a class="dropdown-level1-color menu-left-color" href= "#">Furniture</a>

                                    <ul class= "dropdown-menu sub-menu submenu-hover-color">
                                    <li><a href="2">Table</a></li>
                                        <li><a href="#">Chair</a></li>
                                        <li><a href="#">Cupboard</a></li>
                                    </ul>
                                </li>
                                <li><a class="dropdown-level1-color menu-left-color" href= "#">Couch</a></li>
                                <li><a class="dropdown-level1-color menu-left-color" href= "#">Utensils</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a class= "dropdown-toggle dropdown-menu-hover-color menu-left-color" data-toggle="dropdown" href="#">Books</a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a class="dropdown-level1-color " href= "#">Education</a>
                                    <ul class= "dropdown-menu sub-menu submenu-hover-color">
                                    <li><a href="3">Science</a></li>
                                        <li><a href="#">History</a></li>
                                        <li><a href="#">Geography</a></li>
                                    </ul>
                                </li>
                                <li><a class="dropdown-level1-color" href=
                                "#">Magazines</a></li>
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.nav-collapse -->
            </div>
        </div>
    </div>


  <div class="col-xs-12" style="width:700pt; height:500pt; margin-top:5px; ">
    <div class="row " style="margin-left:75pt;">
      <label class="text-center" style="margin-top:10pt;font-size:14pt;">Highlighted Deals</label>
    </div>
</div>
    <div class="col-xs-2" style="width:100pt;"></div>

    <div class="col-xs-2" style="width:100pt;"></div>

    <div class="push"></div>

    <div class="push"></div>

    <div class="push"></div>

    <div class="push"></div>
    <footer>
<!--Start FooterSection-->
      <div id="footerSection" class="col-xs-12 footer-color footer">
      <div id="blank1"  class="col-xs-2"></div>
    <div id="urls"  class="col-xs-8">

      <div class="col-xs-3">
        <h5 style="color:white; font-weight:bold;">Work with Us</h5>
        <a href="#" class="foot"> Sell on OneTab</a><br>
        <a href="#" class="foot"> Advertise</a><br>
        <a href="#" class="foot"> Affiliate Program</a><br>
        <a href="#" class="foot"> Developers API</a><br>
        <a href="#" class="foot"> Merchant Terms &amp; Conditions</a>
      </div>
      <div class="col-xs-3">
    <h5 style="color:white; font-weight:bold;">Company</h5>
    <a href="#" class="foot"> About OneTab</a><br>
    <a href="#" class="foot"> Jobs</a>
      </div>
      <div class="col-xs-3">
    <h5 style="color:white; font-weight:bold;">Help</h5>
    <a href="#" class="foot">FAQ</a><br>
    <a href="#" class="foot">Return Policy</a><br>
    <a href="#" class="foot">Terms of Use</a><br>
    <a href="#" class="foot">Privacy Statement</a>
      </div>
      <div class="col-xs-3">
    <h5 style="color:white; font-weight:bold;">More</h5>
    <a href="#" class="foot "> Gift Cards</a><br>
    <a href="#" class="foot"> Mobile</a>
      </div>
      <div id="blank2"  class="col-xs-2"></div>
    </div><!--End of urls-->

    <div id="copyright"  class="col-xs-12 text-center">
      <h5 style="color:white;">&copy; 2014 All rights Reserved</h5>
    </div><!--End of copyright-->

      </div><!--End of footerSection-->

    </footer>
    </body>
  </html>

任何帮助将不胜感激。 提前谢谢。

0 个答案:

没有答案