I am a beginner in angular. I am able to make drop down and able to get it value using ng-model. But I need to get different value on input field. If the value of drop down value is blank then input field value is "blank". When drop down value is "one" input filled with "rahul" so I will set these value while checking the value of drop down?
Plunker: http://plnkr.co/edit/wVo9SW8Lc0uVr213grR2?p=preview
<!DOCTYPE html>
<html>
<head>
<link data-require="[email protected]" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script data-require="[email protected]" data-semver="0.10.0" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="app" ng-controller='cntrl'>
<select ng-model="myColor" ng-options="color.name for color in colors"></select>
<button ng-click="getColor()">getvalue</button>
<input type ="text"/>
</body>
<script>
angular.module('app',[]).controller('cntrl',function($scope){
$scope.colors=[{name:"one"},{name:"two"},{name:"tree"}]
$scope.getColor=function(){
alert('--'+$scope.myColor.name)
}
})
</script>
</html>
Is there no way to check value of drop down? Is there any way to check onchange listener in angular? Of is there any if-else condition?