[英]angularjs: why ng-click doesn't seem to evaluate {{}}
In a ng-repeat tag, I have a ng-click which contains a code to be evaluated as follows: 在ng-repeat标记中,我有一个ng-click,其中包含要评估的代码,如下所示:
<div ng-repeat="stage in stages" class="selectable stage stage{{stage.stage}}" ng-click="changePage('plantStages/{{stage.id}}')">
Though in the safari inpector I see the code is evaluated as expected as follows… 尽管在野生动物园检查员中,我看到代码按预期进行了评估,如下所示……
<div ng-repeat="stage in stages" class="selectable stage stage6" ng-click="changePage('plantStages/floraison')">
…a click on the tag goes to unevaluated link as follows: …单击标签会转到未评估的链接,如下所示:
.corn.page.html#/plantStages/{{stage.id}}
Here is the changePage in the controller: 这是控制器中的changePage:
$scope.changePage = function(page) {
var url = "kws.corn.page.html#/"+page;
console.log("Change page "+page+" with url "+url);
document.location.href = url;
};
Since ng-click
is an Angular directive, you don't need to interpolate {{}}
inside it: 由于
ng-click
是Angular指令,因此您不需要在其中插入{{}}
:
ng-click="changePage('plantStages/' + stage.id)"
The above show work and is the preferred way. 以上显示的工作方式是首选方式。
It is true that the inspector shows the interpolated value, but this is too late in the Angular $digest
cycle for the ng-click
to work. 检查器确实显示了插值,但这在Angular
$digest
循环中太晚了, ng-click
无法起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.