这是漫长的一天,我可能错过了一些明显的东西,但是。。。
我有一个ng-repeat单选按钮列表,它反映了到客户位置的实时UPS运费。“隔夜”、"2天“等)
下面是标记:
<div ng-repeat="i in ShippingRates">
<div class='radio'>
<label>
<input value="{{i.Rate}}" ng-model="Cart.ShippingCharge" type="radio" name="shipping-method" ng-click="SetSelectedMethod('Other')" />{{i.ShippingMethod}} <span ng-if="i.Rate > 0">({{i.Rate | currency}})</span></label></div>
</div>我已经有了从ng-model返回的与i.Rate相关的单选按钮(例如,$100)。
现在,我还需要将单选按钮的text存储为"SelectedShippingMethod“。我认为这样做的方法可能是添加这样一个ng-click:
<input value="{{i.Rate}}" ng-model="Cart.ShippingCharge" type="radio" name="shipping-method" ng-click="SetSelectedMethod('{{i.ShippingMethod}}')" />然后这个函数会是这样的:
$scope.SetSelectedMethod = function(method){
$scope.SelectedShippingMethod = method;
}但这是行不通的,因为它会导致$scope.SelectedShippingMethod实际上被设置为"{{i.ShippingMethod}}"。
任何帮助都是非常感谢的。
发布于 2014-05-01 00:34:53
ng单击中的函数已经是一个JavaScript方法,而不是HTML,所以您不必将变量计算为表达式。只需调用变量即可。
例如ng-click="SetSelectedMethod(i.ShippingMethod)"
https://stackoverflow.com/questions/23400331
复制相似问题