下拉菜单显示输入AngularJS中的值

时间:2017-08-11 08:03:19

标签: angularjs twitter-bootstrap

我需要做这样的事情:当你点击前。 &#34;登录&#34;在<ul class="dropdown-menu">中,然后在输入文字中显示来自login的{​​{1}}与$scope.logins相同

password

HTML:

$scope.logins = [{
        "login" : "log",
        "password" : "pass"
    }]

Plunker:http://plnkr.co/edit/g1t4pludTTIAJYKTToCK?p=preview

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

尝试将ng-click添加到li代码和初始value模型。

  <li ng-click="value = logins[0].login"><a >login</a></li>
  <li ng-click="value = logins[0].password"><a >password</a></li>

答案 1 :(得分:0)

&#13;
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="script.js"></script>

<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.min.js"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body>

  <div ng-app="myApp" ng-controller="myCtrl">
    <div class="dropdown">
      <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Type
              <span class="caret"></span></button>
      <ul ng-init="placeholder = ''" class="dropdown-menu">
        <li ng-click="placeholder = 'login'"><a>login</a></li>
        <li ng-click="placeholder = 'password'"><a>password</a></li>
      </ul>
    </div>

    <input class="form-control" name="type" placeholder="{{placeholder}}" ng-model="value">
  </div>
&#13;
        private Boolean isInternetPresent = false;

        isInternetPresent =isConnectingToInternet() ;

        if(isInternetPresent){
            }else{}


       public boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }

    }
    return false;
}
&#13;
&#13;
&#13;