My goal is to set the default value for a dropdown in an Angular HTML Page. The page uses tabs, and I want the default value to load when a specific tab is clicked.
<div class="col-md-9" ng-cloak ng-controller="ServiceTypeController">
<md-content>
<md-tabs md-dynamic-height md-border-bottom md-selected="selectedIndex">
<md-tab label="Details">
<div ng-include="'././Views/Angular/Requests/details.html'"></div>
</md-tab>
<md-tab label="Create Request">
<div ng-include="'././Views/Angular/Requests/createRequest.html'" md-on-select ="clearRequest(requestForm)"></div>
</md-tab>
</md-tabs>
</md-content>
</div>
When the Create Request tab is clicked, it should trigger the clearRequest function. This function is defined as follows:
$scope.serviceReasons = [
{ id: 1, value: 'ABC' },
{ id: 2, value: 'DEF' }
];
$scope.clearRequest = function (form) {
$scope.request = {
serviceReason : "ABC",
};
form.$setPristine();
form.$setUntouched();
};
Below is the code for the Create Request Page:
<form name="requestForm">
<div class="form-group col-md-6 md-padding">
<div class="text-primary">
<h3>Create Request</h3>
</div>
<div>
<label style="font-size: medium">Service Reason</label>
<select name="serviceReason" class="form-control" ng-model="request.serviceReason" required>
<option ng-repeat="serviceReason in serviceReasons">{{ serviceReason.value }}</option>
</select>
<div style="color:maroon" ng-messages="requestForm.serviceReason.$error"
ng-if="requestForm.serviceReason.$touched">
<div ng-message="required">This field is required</div>
</div>
</div>
<div class="md-padding col-md-6">
<div class="row form-group">
<button type="button" class='btn btn-danger' ng-click="clearRequest(requestForm)">Clear</button>
<button type="button" class="btn btn-success" ng-disabled="!requestForm.$valid" ng-click="createRequest(requestForm)">Create</button>
</div>
</div>
</div>
</form>
The clearRequest() function works perfectly from the clear button in the Create Request page. It seems that md-on-select isn't behaving like ng-click - what am I missing here?