1

我正在处理列表视图的无限滚动并使用angular.element(). 每个列表元素都有一个ng-click属性,并且在函数中传递了几个参数,其中一个是作为字符串传递的链接。"http:"因此,由于子字符串中的冒号符号,angular 会抛出语法错误。有谁知道我该如何解决这个问题?我尝试了不同的方法来修复它,但仍然无法解决它。

这就是我创建元素的方式

let newPresentationDiv = angular.element("<div role='presentation' ng-click='openArticle("+ art.source +", "+ art.id +", "+ art.image +", " + art.title +");'></div>")
$compile(newPresentationDiv)($scope) 

这是创建的 HTML:

<div role="presentation" ng-click="openArticle(GI, https://www.gesundheitsinformation.de/eierstockzysten-ovarialzysten.2638.de.atom, null, Eierstockzysten (Ovarialzysten));" class="ng-scope"></div>

这是我得到的错误

Syntax Error: Token ':' is unexpected, expecting [)] at column 22 of
the expression [openArticle(GI, https://www.gesundheitsinformation.de/eierstockzysten-ova..., null, Eierstockzysten (Ovarialzysten))]  
starting at [://www.gesundheitsinformation.de/eierstockzysten-ovarialzysten.2638.de.atom, null, Eierstockzysten (Ovarialzysten].

我试图把链接放进去," "但它没有用。此外,我尝试删除http://字符串的一部分,但我得到字符串中其他字符的错误,我不想操纵链接本身。

任何帮助将非常感激!先感谢您 :))

4

1 回答 1

1

您创建模板的方式存在问题。您需要将'其呈现为字符串值。

<div role="presentation" ng-click="openArticle('GI', 'https://www.gesundheitsinformation.de/eierstockzysten-ovarialzysten.2638.de.atom, null, Eierstockzysten (Ovarialzysten)');" class="ng-scope">Click me</div>

这是plunkr 演示

尝试

let newPresentationDiv = angular.element("<div role='presentation' ng-click=\"openArticle('"+ art.source +"', '"+ art.id +"', '"+ art.image +"', '" + art.title +"')\"></div>")
于 2019-04-28T06:04:22.187 回答