2

我有以下功能:

var app = angular.module('Hubbub-FrontEnd', []);

app.controller('DataEntryCtrl', function($scope) {
   $scope.entryFields = [
       {pHolder:'ID goes here',ngmodel:"kid"},
       {pHolder:'Description goes here',ngmodel:"desc"},
       {pHolder:'Drop Dead Date goes here',ngmodel:"ddd"}
   ];
});

这在下面被调用html

<div ng-controller="DataEntryCtrl">
      <span ng-repeat="entryField in entryFields">
            <input type="text" ng-model="{{entryField.ngmodel}}" placeholder=
"{{entryField.pHolder}}">
   </span>
   <button>Add</button>
</div>
4

1 回答 1

3

使用 ngModel 指令进行双向数据绑定时,您不需要双花括号{{}}。双花括号告诉 angular 评估表达式并打印输出,注意你必须如何使用它们来显示占位符的内容

这是工作版本

<span ng-repeat="entryField in entryFields">
        <input type="text" 
               ng-model="entryField.ngmodel" 
               placeholder="{{entryField.pHolder}}">
</span>

http://jsfiddle.net/jaimem/A8PkC/1/

于 2012-12-03T21:50:27.503 回答