【发布时间】:2015-01-06 16:38:36
【问题描述】:
<div ng-repeat="account in accounts" class="widget-container added_address">
<div id="address-{{$index}}"
class="btc_public_address"
ng-click="pubAddress.getClick(address-{{$index}}">
{{account.address}}
</div>
^ 上面的 div 是一个 ng-repeat,我有大约 4 个 div,它们的 id 分别为:address-1、address-2、address-3 和 address-4 作为 ID。
我尝试在 getClick 函数中简单地传递 ID,但出现以下错误:
错误:[$parse:syntax] http://errors.angularjs.org/1.2.19/$parse/syntax?
应用代码:
$scope.pubAddress = {};
$scope.pubAddress.getClick = function(the_id) {
console.log(the_id);
selectAddress(the_id);
};
// code to select text inside ID (works)
function selectAddress(element) {
var text = document.getElementById(element);
var range = document.createRange();
var selection = window.getSelection();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
};
^ 基本上,我正在尝试使用这些 ID 对我单击的每个 div 中的文本进行简单的选择。
【问题讨论】:
标签: javascript angularjs angularjs-ng-repeat angularjs-ng-click