I have an angular view with a dynamic dropdown. When the user selects one of the options in the list I am trying to set a scope variable. For whatever reason it is not set upon selection. I assume it's an issue with the scope, but I can't figure out what exactly.
app.controller('MyController', function ($scope) {
$scope.myType = null;
$scope.types = [{name: 'a', isChecked:false}, {name: 'b', isChecked:false}, {name: 'c', isChecked:false}];
$scope.doSomething = function() {
console.log($scope.myType); //null value
}
}
The view builds the dropdown from the types scope variable. When the user selects one, I set myType to the name value of the selection, but when I try to reference that variable within the controller, its always null.
<div class="btn-group" dropdown>
<button type="button" dropdown-toggle>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="type in types" ng-click="myType = type.name">
{{type.name}} <input type="checkbox" ng-checked="myType == type.name" /><label></label>
</li>
</ul>
</div>
<div ng-click="doSomething()">do something</div>