I have a small controller in angular that controls a drop down that populates the second drop down depending on the first selection.
I cant seem to get the drop downs populated with any content from my controller, I get no console errors and see no mistake it would be good to get a second pair of eyes to see if they can spot my mistake.
My controller
// our controller for the form
// =============================================================================
.controller('formController', function($scope) {
// we will store all of our form data in this object
$scope.formData = {};
// function to process the form
$scope.processForm = function() {
alert('awesome!');
};
});
var app = angular.module('selection-type', []);
app.controller('SelectCnrl', function($scope) {
$scope.user = {bankName: ''};
$scope.banks = [{
"name": "Bank A",
"branches": [{
"name": "Branch 1",
"code": "1"
}, {
"name": "Branch 2",
"code": "2"
}]
}, {
"name": "Bank B",
"branches": [{
"name": "Branch 3",
"code": "3"
}, {
"name": "Branch 4",
"code": "4"
}, {
"name": "Branch 5",
"code": "5"
}]
}];
});
My HTML
<div ng-app="selection-type">
<div ng-controller="SelectCnrl">
<select ng-model="user.bankName" ng-options="bank.name for bank in banks">
</select>
<select ng-model="user.branch" ng-if="user.bankName"
ng-options="branch.code as branch.name for branch in user.bankName.branches">
</select>
<!--<br /> <br /><br /><br /><br />-->
<!--selected bank : {{ user.bankName }} <br />-->
<!--selected branch : {{ user.branch }}-->
</div>
</div>
<div class="form-group row">
<div class="col-xs-6 col-xs-offset-3">
<a ui-sref="form.end" class="btn btn-block btn-info">
Next Section <span class="glyphicon glyphicon-circle-arrow-right"></span>
</a>
</div>
</div>