ng-model - 绑定到对象中的动态字段

ng-model - bind to dynamic field in object

我有这个代码:

  <div ng-repeat="c in q.children | orderBy:[]">

      <div ng-if="c.kind == 'text'">
        <label>
          {{c.value}}
          <textarea ng-model="q.newResponse.value['{{c._id}}']"></textarea>
        </label>
      </div>

  // ...

我想做的是在 newReponse.value 上绑定一个 属性,其中 属性 是动态的并且是 c._id 值,所以类似:

newResponse.value.44PkfeoakfoAf5o3r3773oZS3a = 'foo bar baz';

这不能正常工作,我得到这个错误:

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 22 of the expression [q.newResponse.value[{{c._id}}]] starting at [{c._id}}]].
http://errors.angularjs.org/1.6.1/$parse/syntax?p0=%7B&p1=invalid%20key&p2=22&p3=q.newResponse.value%5B%7B%7Bc._id%7D%7D%5D&p4=%7Bc._id%7D%7D%5D
    at angular.js:68
    at AST.throwError (angular.js:14893)
    at AST.object (angular.js:14882)

这可能吗?正确的方法是什么?

没关系,这并不难 -

      <div ng-if="c.kind == 'text'">
        <label>
          {{c.value}}
          <textarea ng-model="q.newResponse.value[c._id]"></textarea>
        </label>
      </div>