How do i set the default value of a radio input?
ctrl.teamSelectionOption = {value:'createTeam'};
Then update it when the data returns from the server ?
ctrl.teamSelectionOption = {value:'chooseTeam'};
From the template, How do i check which input has been selected?
<button class="btn btn-sm btn-primary" ng-click="$ctrl.getTeamOption($ctrl.teamSelectionOption.value)" >Select</button>
These questions are all very closely related. This is roughly what i have now:
(function(angular) {
'use strict';
angular.module('app').component('bringTeamToEvent', {
templateUrl: '/assets/ng/app/team/bringTeamToEvent.html',
bindings: {
teamSelectionOption: '<',
teamFeesPanel: '<'
},
controller: function($http){
var ctrl = this;
ctrl.teamFeesPanel = false;
ctrl.teamSelectionOption = {value:'createTeam'};
$http({
method: 'GET',
url: '/team',
}).then(response => {
this.teams = response.data;
// console.log(response.data);
}, response => {
if(ctrl.teams.length > 0 ? true : false){
ctrl.teamSelectionOption = {value:'chooseTeam'};
}
if(ctrl.teams.length == 0 ? true : false){
ctrl.teamSelectionOption = {value:'createTeam'};
}
});
<div class="teamSelectionPanel" ng-show="!$ctrl.teamFeesPanel">
<div ng-if='$ctrl.teams.length > 0'>
<input ng-model="$ctrl.teamSelectionOption.value" type="radio" name="team" value="chooseTeam" ng-checked="($ctrl.teamSelectionOption.value==chooseTeam)">
<label for="chooseTeam">Choose an existing team</label><br>
<select class="form-control" ng-model="$ctrl.teamSelection" ng-options="team.name for team in $ctrl.teams track by team.id">
<!-- ng-change="$ctrl.onTeamSelectCallback(value)" -->
</select><br>
</div>
<!-- active? -->
<input ng-model="ctrl.teamSelectionOption.value" type="radio" name="team" value="createTeam" ng-checked="($ctrl.teamSelectionOption.value==createTeam)">
<label for="createTeam">Create new team</label><br>
</div>
example plunker: https://plnkr.co/edit/8B59uBiz6sJ2x6CK?preview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…