Angular ng-model不绑定到select

时间:2015-03-11 16:38:29

标签: angularjs

我从我的数据库中提取了一个帐户列表,并使用该信息进行选择下拉列表,显示名称,并将id作为值。一切正常,但是,一旦我尝试将其发送到我的控制器以发布到我的API,就没有来自或来自帐户。我在这两个领域都有ng-model,但它似乎没有做任何事情。

这是我的HTML

    <form novalidate>
    <div ng-controller="newTransactionController">
         <div >
             <label for="from">From Account</label>
             <select name="from" ng-options="acct as acct.label for acct in options" ng-model="transaction.fromAccount" > 
                <option value="acct.value"> </option>
            </select>
        </div>

        <div>
            <label for="to">To Account</label>
            <select name="to">
                <option ng-repeat="account in accounts" value="{%account._id%}" ng-model="transaction.toAccount">{%account.name%}</option> 
            </select>
        </div>
    </div>

    <div>
         <label for="amount">Amount</label>
         <input type="text" name="amount" id="amount" value="" tabindex="1" ng-model="transaction.amount"/>
    </div>

   <div>
        <label for="currency">Currency</label>
        <select name="currency" ng-model="transaction.currency">
            <option value="USD">USD</option>
            <option value="BTC">BTC</option>
        </select>
    </div>

    <div>
         <label for="interval">Interval</label>
         <input type="text" name="interval" id="interval" value="" tabindex="1" ng-model="transaction.interval"/>
    </div>

   <div>
         <label for="processDate">Process Date</label>
         <input type="text" name="processDate" id="processDate" value="" tabindex="1" ng-model="transaction.processDate"/>
    </div>

  <div>
        <input class="button" type="submit" value="Send" ng-click="createTransaction(transaction)"/>
    </div>
</form>

我的控制器

    $http.get('').success(function(data){
    $scope.accounts = data;
    var options = $scope.options = [];

    for(var i=0; i < data.length; i++){
        $scope.options.push({label: data[i].name, value: data[i]._id});
    }
});

$scope.createTransaction = function(transaction){

    var transactions = {
         fromAccount: angular.copy(transaction.fromAccount),
         toAccount: angular.copy(transaction.toAccount),
         amount: angular.copy(transaction.amount),
         currency: angular.copy(transaction.currency),
         interval: angular.copy(transaction.interval),
         processDate: angular.copy(transaction.processDate)
    };


    $http.post('', transactions).success(function(){console.log('sent')});
};

当我在控制器中注销交易时,我得到的只是:对象{金额:“1”,货币:“美元”}

我迷路了。我无法弄清楚这里缺少什么。

1 个答案:

答案 0 :(得分:0)

发现我的问题。围绕<div>to帐户的from标记是一个范围问题。