将AngularJS变量分配给html的name标记

时间:2014-03-25 17:53:26

标签: html angularjs

{{item.name1}}item_name_1

{{item.description}}Band

案例1

<input name="item_name_1" value={{item.description}}> 

文本字段包含Band

案例2

<input  name={{item.name1}} value={{item.description}}>

文本字段不包含任何内容。

案例2的任何解决方案?

完整代码

HTML

<div ng-app="myApp" ng-controller="myController">
    <form style="float:right" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
          <input type="hidden" name="cmd" value="_xclick">
          <input type="hidden" name="business" value="info@dialswap.com">
          <input type="hidden" name="lc" value="US">


          <!--Code to be Seen below --> 
          <div ng-repeat="items in item" >
               <input type="hidden" name="{{items.name}}" value={{item.description}}>
               <input type="hidden" name="{{items.amount}}" value=60>
          </div>


          <input type="hidden" name="currency_code" value="USD">
          <input type="hidden" name="button_subtype" value="services">
          <input type="hidden" name="no_note" value="0">
          <input type="hidden" name="cn" value="Add special instructions to the seller:">
          <input type="hidden" name="no_shipping" value="2">
          <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
          <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
          <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">  
        </form>

</div>

AngularJS

var app = angular.module('myApp', []);
app.controller('myController', function($scope){
$scope.item[0] = {
    name: 'item_name_1',
    amount:'amount_1',
    description: 'bands'
}
$scope.item[1] = {
    name: 'item_name_2',
    amount:'amount_2',
    description: 'bands'
}
});

JS小提琴http://jsfiddle.net/wedE5/2/

这与一个项目完美配合,没有ng-repeat。

1 个答案:

答案 0 :(得分:0)

您应该使用ng-attr-name="item.name"ng-attr-value="item.value"