在角度js中将字符串转换为int

时间:2017-01-31 06:45:53

标签: html angularjs

这里我试图将ticketPrice(ng-model)和selceted numberOfTickets(ng-model)相乘,但我总是得到NAN总数

<tr>
     <td ng-model="ticketPrice">5</td>
     <td>
       <select class="form-control" ng-model="numberOfTickets" 
            ng-options="n for n in [] | range:1:15"  >
           <option value="">--Select No. of Tickets--</option>                                                    
       </select>
     </td>
     <td class="text-primary text-center"><strong ng-model="ticketsTotalPrice">{{ ticketPrice * numberOfTickets }} </strong></td>
    </tr>

请提供解决方案

谢谢!

2 个答案:

答案 0 :(得分:1)

点击此处查看小提琴示例

<span ng-init="price=100" ></span>
<select name="" id="" ng-model="noOfTic">
  <option value="" selected>select ticket</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>
{{price * noOfTic}}

Fiddle link

答案 1 :(得分:0)

使用ng-bind not ng-model

<strong ng-bind="ticketPrice * numberOfTickets"></strong>