0

我有AuthenticationController一个<div>. 我试图打印{{ email }}两次,但它只显示第二次。

<div class="login" ng-controller="AuthenticationController">
    <!-- This DOESN'T show -->
    {{ email }}

    <div ng-switch on="isLoggedIn()">

        <div ng-switch-when="true">
            <input ng-click="logout()" type="submit" value="Logout">
        </div>

        <div ng-switch-when="false">
            <!-- This IS shown -->
            {{ email }}

            <input ng-model="email" type="text">
            <input ng-model="password" type="password">
            <input ng-click="login()" type="submit" value="Login">

        </div>
    </div>

</div>

为什么第一个{{ email }}不打印?

4

1 回答 1

1

ngSwitch创建一个新的范围。尝试使用一个对象:

<div class="login" ng-controller="AuthenticationController">    
    {{user.email}}
    <div ng-switch on="isLoggedIn()">
        ...
        ... 
        <input ng-model="user.email" type="text">

控制器:

$scope.user = {
    email:""
};
于 2013-11-13T14:39:48.750 回答