2014-02-06 28 views
0

我對AngularJS有問題。在我的表單中,我有幾個輸入。我必須對數據做一些數學計算,然後保存它。但是因爲我使用Angularfire,我不得不將結果分配給ng模型,這就是我卡住的地方。我怎樣才能做到這一點?用數學設置Ng模型數據

這裏是我的代碼:

<label>First</label> 
    <input name="firstmatch" ng-model="project.firstmatch"> 

    <label>Second</label> 
    <input name="secondmatch" ng-model="project.secondmatch"> 

    <label>Third</label> 
    <input name="thirdmatch" ng-model="project.thirdmatch"> 

    <label>Fourth</label> 
    <input name="fourth" ng-model="project.fourthmatch"> 

    <label>Fifth</label> 
    <input name="fifthmatch" ng-model="project.fifthmatch"> 

    <!-- The math part--> 
<textarea name="points" ng-model="project.points"> {{ project.firstmatch--project.secondmatch--project.thirdmatch--project.fourthmatch--project.fifthmatch }} </textarea> 

謝謝!

+0

是的,數學部分看起來很瘋狂,但是輸出所需的數據。 –

+0

你在哪裏分配 – Satpal

+0

我嘗試了很多方法,這是一個:

回答

1

爲什麼你在textarea中打印結果? Textareas默認不接受代碼。只要嘗試在div或跨度上打印結果。

如果您以任何方式希望結果是可編輯的,則將其打印在另一個輸入中,而不要在其中進行計算。執行邏輯控制器,就像這樣:

<label>First</label> 
    <input name="firstmatch" ng-model="project.firstmatch"> 

<label>Second</label> 
    <input name="secondmatch" ng-model="project.secondmatch"> 

<label>Third</label> 
    <input name="thirdmatch" ng-model="project.thirdmatch"> 

<label>Fourth</label> 
    <input name="fourth" ng-model="project.fourthmatch"> 

<label>Fifth</label> 
    <input name="fifthmatch" ng-model="project.fifthmatch"> 

<!-- The math part--> 
<input type="text" name="points" ng-model="project.points" /> 

,比控制器寫:

$scope.project.points = $scope.project.firstmatch - $scope.project.secondmatch - $scope.project.thirdmatch - $scope.project.fourthmatch - $scope.project.fifthmatch; 
+0

Thnx!有用! –

+1

沒問題。你能接受我的回答嗎? – bbahov