这可能很简单,但我找不到合适的文档来解释如何克服我的问题,这里有:我有一个类似于这样的中继器...AngularJS在curley括号中返回变量名称,而不是值
<tr ng-repeat="thing in things">
<td>{{ thing.name }}</td>
<td>{{ thing.category }}</td>
<td>{{ thing.content }}</td>
<td>{{ thing.confirms }}</td>
<td>{{ thing.declines }}</td>
<td> <button ng-click="doSomething('{{ thing }}')">Do what we want</button></td>
</tr>
现在,所有的工作都很好,并且期待。在我写过的服务中的doSomething
函数中,我希望将'thing'对象作为参数传递给一个字符串以避免错误(稍后将进行转换)。现在,当我将该对象输出到我的服务时,不会返回对象内容(尽管它们以呈现的HTML显示)。什么是传递给我的服务是字符串“{{事}}”不是对象的值(所以我JSON.parse失败),这从Chrome浏览器开发工具所提供的HTML:
doSomething('{"name":"Debbie Harry","id":"526f9eb7e4b0b5062e14c1dc","category":"Basic Info","content":"Debbie Harry is cool","confirms":5,"declines":0}')
我将如何克服这一?如何确保JSON对象被传递,而不是AngularJS大括号声明?
如果我不是很好地解释我自己,请写明我的意思,我会重新提出我的问题。
它的工作原理!但为什么? –
我详细阐述了我的答案。 –