Plunkr : http://plnkr.co/edit/BRQ3I4hFTlgKq4Shz19v?p=preview
I'm attempting to pass the selected item from a dropdown to a function within my controller.
Unfortunately, I keep receiving it as undefined.
HTML :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<div ng-app="MyApp" ng-controller="MyController">
<select ng-model="ddlFruits"
ng-options="fruit.Id as fruit.Name for fruit in Fruits track by fruit.Id"
ng-change="GetValue(fruit)">
</select>
</div>
</body>
</html>
Script :
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $window) {
$scope.Fruits = [{
Id: 1,
Name: 'Apple'
}, {
Id: 2,
Name: 'Mango'
}, {
Id: 3,
Name: 'Orange'
}];
$scope.GetValue = function (fruit) {
alert(fruit);
}
});