Ich versuche, die Angularjs Bootstrap Dropdown-Toggle auf einem Formular zu verwenden, und ich muss in der Lage sein, das ausgewählte Element an ein Modell für eine neue "Organisation" zu binden in meiner Bewerbung.Bind Angular JS UI-Bootstrap-Dropdown-Toggle zu ng-Modell
Hier ist mein js Modul ich alle meine Steuerelemente erstellen bin mit:
var Controls = angular.module('PulseControls', ['ui.bootstrap']);
var booleanButtonCtrl = function($scope) {
$scope.radioModel = true;
};
var currencyDropDownButtonCtrl = function($scope) {
$scope.currencies = [{
id: 1,
name: 'US Dollar'
}, {
id: 2,
name: 'Euro'
}, {
id: 3,
name: 'Australian Dollar'
}];
};
Hier ist mein Ausgangscode für meine CreateNewOrganisation Controller
function CreateOrganisationController($scope, $http, $window) {
$scope.newOrganisation = {
isActive: true,
};
und schließlich, hier ist mein HTML-Code-Schnipsel, die enthält eine für "Status" und eine für Währung, die beide Ui-Bootstrap ...
<div class="form-group">
<label class="control-label">Status</label><br />
<div ng-controller="booleanButtonCtrl">
<div class="btn-group">
<button type="button"
class="btn btn-primary"
data-ng-model="newOrganisation.isActive"
btn-radio="true">
Active
</button>
<button type="button"
class="btn btn-primary"
data-ng-model="newOrganisation.isActive"
btn-radio="false">
Dormant
</button>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Currency</label>
<div class="dropdown" data-ng-controller="dropDownButtonCtrl">
<div class="btn-group">
<a class="btn btn-primary dropdown-toggle">Please select<span class="caret"></span></a>
<ul class="dropdown-menu">
<li ng-repeat="currency in currencies">
<a ng-model = "newOrganisation.currency">{{currency.name}}</a>
</li>
</ul>
</div>
</div>
</div>
Der im Status verwendete Ansatz funktioniert gut, aber das Dropdown-Steuerelement für die Währung funktioniert nicht. Irgendwelche Vorschläge?
Können Sie einen Plunker mit Ihrem Code posten? Es wäre viel einfacher zu beheben. – kl02