i have a big problem with angularjs. Here is my code:
Controller:
function testCt($scope){
$scope.types = [
{name:'fruit',label:'To Fruit'},
{name:'meat',label:'To Meat'},
{name:'other',label:'To Other'}
];
$scope.foods = [
{name:'apple',type:'fruit'},
{name:'raptor',type:'meat'}
];
$scope.selected = null;
$scope.selectFood = function(food) {
$scope.selected = food;
}
};
And the view:
<div ng-app ng-controller="testCt">
<ul>
<li ng-repeat="food in foods" ng-click="selectFood(food)">
{{food.name}}
</li>
</ul>
<select data-ng-model='selected' data-ng-options='t.name as t.label for t in types'></select>
<br>
{{selected.name}} <br> {{selected.type}}
</div>
The problem is, the angular js not binding to select element the food what i clicked. Here is the fiddle: http://jsfiddle.net/p7JJs/
When i choose one food from list, the select element not bind to type. Thank for help :)