如何在更改事件中读取对象的属性

how to read a property of an object in change event

这是我的第一个 angular 应用程序...我必须说我对这个框架的强大感到惊讶。任务是建立一个价格计算器,它将在选择一个州后应用州税。这就是我的 JS

function testApp($scope){
    $scope.quantity = 1;
    $scope.price = 10.99;

    $scope.states = [
        {stateName:'--'},
        {stateName:'New York',stateId: 'NY', tax: 0.5},
        {stateName:'Pennsylvania', stateId: 'PA', tax: 0.3},
        {stateName:'California', stateId: 'CA', tax: 0.6}
    ];
}

我的标记如下所示

<div ng-app="" ng-controller="testApp">
Quantity: <input type="number" max="5" ng-model="quantity"/>
Price: <span class="price">{{price|currency}}</span>

State: 
<select>
  <option ng-repeat="x in states" id="{{x.stateId}}">
    {{x.stateName}}
  </option>
</select>

    <h2 id="greeting">Total: {{quantity*price|currency}}</h2>
</div>

我无法全神贯注地思考如何读取州对象的税收属性以及如何更改并将其传递给总计。也许很简单,我在概念上无法理解

这是我的小提琴

http://jsfiddle.net/sghoush1/ssuybyzc/2/

查看 data-ng-options。您不应该那样构建 select。这是更新后的 html:

<select data-ng-model="selectedState" data-ng-options="state as state.stateName for state in states">

连同您更新后的 fiddle:http://jsfiddle.net/dLb9kx6q/