[英]Sending iterator of ng-repeat as an argument to a function
我在下面的代码中尝试使用ng-repeat遍历数组,并将迭代器作为参数发送给函数。
a)创建一个数组stepTitle。
b)使用ng-repeat遍历steptitle.Iterator是'temp'
c)将temp作为参数发送给函数getTitle。
问题-如何在ng-repeat标签内向此函数发送参数。 调用stepTitle(temp)不起作用。 程式码片段:
Directive.displaySteps = ['baseClass',
function(compBase) {
return {
controller: function($scope,$element,$attrs) {
$scope.steptitle =["Step1", "Step2", "Step3"];
},
restrict: "E",
replace: true,
template: function(elem,$attrs) {
return('<div>'+
'<ul class="nav" ng-repeat="temp in steptitle">'+
'<li >'+
'<a class="active" id="anchor" href="javascript:void">'+
'<span class="ps-icn-single-start" id="step1_span"/>'+
'<span>{{'+ getTitle(temp)+'}}</span>'+
//'<span>{{temp}}</span>'+
'</a>'+
'</li>'+
'</ul>'+
'</div>');
}
您正在模板创建过程中调用该函数,不应调用该函数,而应先对其进行编译然后再调用。 因此,将您的代码更改为此:
Directive.displaySteps = ['baseClass',
function(compBase) {
return {
controller: function($scope,$element,$attrs) {
$scope.steptitle =["Step1", "Step2", "Step3"];
},
restrict: "E",
replace: true,
template: function(elem,$attrs) {
return('<div>'+
'<ul class="nav" ng-repeat="temp in steptitle">'+
'<li >'+
'<a class="active" id="anchor" href="javascript:void">'+
'<span class="ps-icn-single-start" id="step1_span"/>'+
'<span>{{getTitle(temp)}}</span>'+
//'<span>{{temp}}</span>'+
'</a>'+
'</li>'+
'</ul>'+
'</div>');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.