Sto appena iniziando a giocare con AngularJS e sto cercando di capire la tecnica di rilegatura. Per cominciare, ho provato a fare un semplice calcolatore di conversione (dozzine di pezzi, pezzi a dozzine). Che funzionava bene, ma quando ho cercato di legare sia gamma ingresso ed un ingresso numero alla stessa proprietà modello il numero ingresso non aggiorna quando il valoregamma viene regolata. Ho una jsfiddle che mostra il comportamento:Associazione a due vie con intervallo e immissione di numeri in AngularJS
JavaScript comune per fiddles lavoro rotti e:
var myApp = angular.module('myApp', []);
myApp.controller('CalcCtrl', function ($scope) {
var num = 0.0;
$scope.qty = new Quantity(12);
$scope.num = num;
});
function Quantity(numOfPcs) {
var qty = numOfPcs;
var dozens = numOfPcs/12;
this.__defineGetter__("qty", function() {
return qty;
});
this.__defineSetter__("qty", function (val) {
qty = val;
dozens = val/12;
});
this.__defineGetter__("dozens", function() {
return dozens;
});
this.__defineSetter__("dozens", function (val) {
dozens = val;
qty = val * 12;
});
}
html:
<div ng-controller="CalcCtrl">
<form>
<label for="pcs">Pieces:</label>
<input type="number" min="0" ng-model="qty.qty" size="20" id="pcs"
/>
<input type="range" min="0" max="100" ng-model="qty.qty" />
<br/>
<label for="numOfDozens">Dozens</label>
<input type="number" min="0" ng-model="qty.dozens" size="20"
id="numOfDozens" />
</form>
</div>
Tuttavia, vincolante due numero ingressi la stessa proprietà del modello sembra funzionare bene come mostrato in questo violino:
html:
<div ng-controller="CalcCtrl">
<form>
<label for="pcs">Pieces:</label>
<input type="number" min="0" ng-model="qty.qty" size="20" id="pcs"
/>
<input type="number" min="0" max="100" ng-model="qty.qty" />
<br/>
<label for="numOfDozens">Dozens</label>
<input type="number" min="0" ng-model="qty.dozens" size="20"
id="numOfDozens" />
</form>
</div>
Delle idee come ottenere una gamma e numero ingresso legato a una singola proprietà modello AngularJS? Grazie.
Non credo type = "range" è supportato: https://github.com/angular/angular.js/issues/1189 Probabilmente dovresti scrivere la tua direttiva per questo. –