0

我是 angularJs 的新人,所以我看到很多帖子如何制作控制器等,但是在每个控制器中,我们传递范围以获取在处理控制器的特定视图中定义的特定值。我正在发送我的代码,为什么我没有得到我的在我调试时使用 $scope 查看值,并且想要获取值 $scope.LoginName 错误:- 未定义无法读取属性。

它正在访问 $scope.loggedIn 但不访问登录视图值。

索引.html

<body ng-controller="LoginController">

    <div ng-switch="loggedIn">
      <div ng-switch-when="false">
        <div class="navbar navbar-inverse navbar-static-top">
            <div class="container">
                <a href="#" class="navbar-brand"><b>Consumely</b></a>

                <div class="collapse navbar-collapse navHeaderCollapse">
                    <ul class="nav navbar-nav navbar-right" data-ng-controller ="inventoryNavController">
                        <li data-ng-class="{'active':getClass('/Login')}"><a href="#/Login">Login</a></li>
                        <li data-ng-class="{'active':getClass('/SignUp')}"><a href="#/SignUp">SignUp</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div ng-view class="viewStyle"></div>
      </div>

      <div ng-switch-when="true">
        <div class="navbar navbar-inverse navbar-static-top">
            <div class="container">
                <a href="#" class="navbar-brand"><b>Consumely</b></a>
                <div class="collapse navbar-collapse navHeaderCollapse">
                    <ul class="nav navbar-nav navbar-left">
                        <li class=""><a ng-click='logout()' >Log Out</a></li>
                        <li><a href="#">Send Invite</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li data-ng-class="{'active':getClass('/Stores')}"><a href="#/Stores">Stores</a></li>

                    </ul>
                </div>
            </div>
        </div>
        <div ng-view class="viewStyle"></div>
      </div>
    </div>


    <!-- Controllers -->

    <!-- login Controller -->
    <script src="app/controllers/loginController.js"></script>

    <!-- services -->

    <!-- login service -->
    <script src="app/services/loginService.js"></script>

  </body>

登录视图.html

<div class="form-group">
                        <label for="login-Name" class="col-lg-3 form-label">User Name:</label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" id="login-Name" ng-model="LoginName" name="login-Name" placeholder="User Name"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="login-Password" class="col-lg-3 form-label">Password:</label>
                        <div class="col-lg-8">
                            <input type="password" class="form-control" id="login-Password" ng-model="LoginPass" name="login-Password" placeholder="Password"/>
                        </div>
                    </div>

登录控制器.js

app.controller('LoginController', function ($rootScope, $scope, loginService, $location) {

    $rootScope.loggedIn = false;

      $scope.login = function() {

          var user = {
              "username" : $scope.LoginName,
              "password" : $scope.LoginPass
          }
      }; 
});

如果有人知道请帮助我。

4

0 回答 0