-2

I need to do something like this : When you select ex. "login", then in input text shows login from $scope.logins . The same with password

JS:

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


    $scope.onSelectBoxChange = function(selectedValue){
     if(selectedValue=="login"){
    $scope.value = $scope.logins[0].login;
     }else{
    $scope.value=undefined;
  }
}

HTML :

 <ul>

      <li><button ng-model="type" ng-change="onSelectBoxChange(type)">login</button>
      </li>
      <li><button ng-model="type" ng-change="onSelectBoxChange(type)">password</button>
      </li>
 </ul>

<input class="form-control" name="type" placeholder="value" ng-model="value" style="margin-bottom:5px;">

My code doesn't work. Thanks for answers in advance!

3
  • 2
    In the button tag you should use ng-click not ng-change Commented Aug 9, 2017 at 10:11
  • Possible duplicate of Select shows value in input AngularJS Commented Aug 9, 2017 at 10:12
  • pls write your working code , and also if any error coming . Commented Aug 9, 2017 at 10:13

2 Answers 2

0

You have used ng-change. Instaed you should use ng-click, ad button fires click event.

 <ul>
      <li><button ng-model="type" ng-click="onSelectBoxChange(type)">login</button>
      </li>
      <li><button ng-model="type" ng-click="onSelectBoxChange(type)">password</button>
      </li>
 </ul>
<input class="form-control" name="type" placeholder="value" ng-model="value" style="margin-bottom:5px;">
Sign up to request clarification or add additional context in comments.

Comments

0

As mentioned in the comment by @Anita, the ng-change should be changed to ng-click. ng-change is used for elements like dropdown, where there is an action involved when there is a change in value. DUring the click event, there is no such change in the value, hence there wont be any function implementation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.