2016-10-06 18 views
0

このanglejsアプリケーションでは、ユーザーがユーザー名とパスワードを入力するログインページが最初にあります。アプリケーションに入ると、データベースアクセスのために別のユーザー名とパスワードが必要な別のページを選択できます。私はデータベースのユーザ名を、ログインとパスワードとは異なる値にデフォルト設定し、プレースホルダがEnter a passwordの空白にしたい。ただし、データベースページのデフォルトでは、初期ログイン値が使用されています。
これは、ログインページのHTMLです:html角度アプリケーションでデフォルト値が正しくありません

<div class="form-group"> 
     <label for="username" class="col-sm-2 control-label">Username</label> 
     <div class="col-sm-10"> 
      <input type="text" class="form-control" id="username" name="username" placeholder="Username" style="width: 80%" autofocus ng-model="credentials.username" /> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="password" class="col-sm-2 control-label">Password</label> 
     <div class="col-sm-10"> 
      <input type="password" class="form-control" id="password" name="password" placeholder="Password" style="width: 80%" ng-model="credentials.password" /> 
     </div> 
     </div> 

これは、データベース・ログインのhtmlです:

<div class="row" style="margin-top: 10px; margin-bottom: 10px;"> 
          <label id="inputDBUserNameLabel" style="margin-left: 10px;" >User Name: </label> 
          <input id="inputDBUserNameText" type="text" ng-model="inputUserName" class="form-control demoInput" value="test" style="margin-left: 5px; width: 25%;"/> 
         </div> 
         <div class="row" style="margin-top: 10px; margin-bottom: 10px;"> 
          <label id="inputDBPasswordLabel" style="margin-left: 10px;" >Password: </label> 
          <input id="inputDBPasswordText" type="password" ng-model="inputPassword" class="form-control demoInput" placeholder="Enter a password" style="margin-left: 5px; width: 25%;"/> 
         </div> 

は私が間違って何をしているのですか?

更新 以下は、データベースに接続するときのコントローラのコードです。正しいユーザ名とパスワードを入力するとき
は、それが動作します:

'use strict'; 

angular.module('vow-administration-ui') 
    .controller('UpgradeCtrl', ['$scope', 'UpgradeDB', 
     function($scope, upgradeDB) { 
     $scope.title = "Upgrade Database"; 

     $scope.inputServerName = ''; 
     $scope.inputDatabaseName = ''; 
     $scope.inputUserName = ''; 
     $scope.inputPassword = ''; 

     $scope.outputServerName = ''; 
     $scope.outputDatabaseName = ''; 
     $scope.outputUserName = ''; 
     $scope.outputPassword = ''; 

     $scope.UpgradeDatabase = function(){ 

     upgradeDB.save({ 
      inputServerName: $scope.inputServerName, 
      inputDatabaseName: $scope.inputDatabaseName, 
      inputUserName: $scope.inputUserName, 
      inputPassword: $scope.inputPassword, 

      outputServerName: $scope.outputServerName, 
      outputDatabaseName: $scope.outputDatabaseName, 
      outputUserName: $scope.outputUserName, 
      outputPassword: $scope.outputPassword 

     }).$promise.then(function(response) { 
      var responseText = response; 
      console.log(responseText); 
     });     
     }; 

    }]); 

UPDATE 私は期待値にng-model=inputUserNameとの両方のユーザー名とパスワードのフィールドが変更されたを削除しました。パスワードフィールドからng-model属性を削除していなくても、ユーザー名フィールドのデフォルト値はtestで、パスワードフィールドのプレースホルダはEnter a passwordでした。

UPDATE ログインコントローラー:

angular.module('vow-administration-ui') 
    .controller('LoginCtrl', function($scope, $rootScope, $location, AUTH_EVENTS, AuthService) { 

    $scope.isProcessing = false; 

    $scope.credentials = { 
     domain: '', 
     username: '', 
     password: '' 
    }; 



$scope.login = function() { 
     AuthService.authenticateAdministrator($scope.credentials).then(function() { 
      $scope.errorMessage = ''; 
      $scope.errorState = false; 
      $location.path('/launch').replace(); 
     }, 
     function(error) { 
      AuthService.destroyToken(); 
      $scope.errorMessage = 'Failed to authorize. ' + error.data.ExceptionMessage; 
      $scope.errorState = true; 
     }); 
    }; 

    }); 
+0

コントローラ(imo)で何かが起こっている必要があります。私たちはそれを見ることができますか? – defaultcheckbox

+0

私はデータベースのコントローラのコントローラを追加しました。 –

+0

hmm ..私にはうまく見えます。あなたはjsbinやplunkrできますか?なぜinputUserNameがcredentials.usernameと同じ値を持つのかわかりません。多分私はあなたの質問を誤解していますか?私はjsbinまたはplunkrが問題を明確にするのに役立つと思います。 – defaultcheckbox

答えて

0

それが問題だったというGoogle Chromeのです... を問題を修正しました。 「username」と「password」という形式のIDを使用すると、ユーザー名とパスワードとして使用されていた前のテキストを挿入することで、Chromeは「ヘルプ」を試みます。

問題を解決するために、ng-modelの名前をUsrNmとPwdのバリエーションに変更しました。

これで動作します。

+0

だから、要素IDと要素名ではなく、パスワードのインスタンスのNGモデルを調べていましたか?良い見つける。 – defaultcheckbox

+0

ブラウザのChromeを使用している場合は明らかです –

関連する問題