AngularJs没有将范围变量赋予特定控制器

时间:2013-11-07 14:32:00

标签: javascript angularjs

我是angularJs的新手,所以我看到很多人发布了如何制作控制器等但是在每个控制器中我们都通过范围获取特定值,这些值在特定视图中定义,它处理controller.i我发送的代码为什么我不要当我正在进行debuging时,使用$ scope获取我的视图值并且想要获取值$ scope.LoginName 错误: - 未定义无法读取属性。

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

的index.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>

LoginView.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>

loginController.js

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

    $rootScope.loggedIn = false;

      $scope.login = function() {

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

如果有人知道帮助我,请好心。

0 个答案:

没有答案