如何在html中将angularjs中的两个值相乘

时间:2016-03-03 08:55:52

标签: javascript html angularjs

我正在研究AngularJS的演示,它可以转换两个单元。基本上我有两个单位值的下拉列表,并希望将下拉列表中的选定值相乘。我为我的代码创建了一个jsfiddle,任何人都可以帮我解决它。

拨弄

fiddle HTML:

<div ng-controller="MyCtrl">
    <div ng-repeat="address in addresses">
        Billing State:
        <select
            ng-model="address.state"
            ng-options="state.lookupCode as state.description for state in lov_state"></select>
        <tt>State selected: {{address.state}}</tt>
    </div>

</div>

AngularJS:

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope) {

    $scope.addresses = [
        {'state': 'AL'},
        {'state': 'CA'},
        {'state': 'FL'}
    ];

    $scope.lov_state = [
        {'lookupCode': 'AL', 'description': 'Alabama'},
        {'lookupCode': 'FL', 'description': 'Florida'},
        {'lookupCode': 'CA', 'description': 'California'},
        {'lookupCode': 'DE', 'description': 'Delaware'}
    ];
});

我的小提琴代码如下: My JSFiddleworking demo

1 个答案:

答案 0 :(得分:-1)

如此接近!只是忘了做总和

更新小提琴here

你错过了= {{address.state * unit.state}}